Hi,
I have big database with ~400 tables and ~300 views. Going to start using MVC/EF. Selected ASP.NET Boilerplate as framework. As I can understand best approach for me use 'Database First' model.
- Have created .edmx, customized T4 templates to inherit generated classes from Abp.Domain.Entities.Entity.
- My dbContext file inherits from AbpDbContext.
Have following code:
public class ArticlesAppService : TWAppServiceBase, IArticlesAppService
{
private readonly IRepository<Articles_T> artRepository;
public ArticlesAppService(IRepository<Articles_T> artRepository)
{
this.artRepository = artRepository;
}
public Articles_T Get(int id)
{
return artRepository.Get(id);
}
}
and when I execute Get method - have an error:
_An exception of type 'System.ApplicationException' occurred in EntityFramework.DynamicFilters.dll but was not handled in user code
Additional information: Filter name MustHaveTenant not found_
Are there any ideas what is wrong ?
5 Answer(s)
-
0
does your dbcontext overrides onmodelcreating? if so, it should call the base method. I suggest Code-First instead of Db-First. If you have problems you can search in the forum for it.
Have a nice day.
-
0
Generated using Code-First templates. Seems that problem solved.
But currently have another issue:
IRepository<> accepts type inherited from Entity which defines primary column as 'Id' int.
Tables in my DB uses different names: ID, [TableName]Id etc
Is it possible to override this ?
-
0
Have update on this. Found workaround solution here: <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/issues/586">https://github.com/aspnetboilerplate/as ... issues/586</a>
Done as follows:
public partial class Articles_T : IEntity<int>
and
#region Implementation of IEntity<int> public bool IsTransient() { return false; } [NotMapped] public int Id { get { return Articles_ID; } set { Articles_ID = value; } } #endregion
When execute
Articles_T art = artAppService.Get(articleId);
Get error:
An exception of type 'System.NotSupportedException' occurred in EntityFramework.SqlServer.dll but was not handled in user code Additional information: The specified type member 'Id' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.
-
0
Hi,
Instead of [NotMapped], use [Column("YourTableId")] to specify Id field.
-
0
Works! Many thanks :)