Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Attempt to use Boilerplate with existing database. #601


User avatar
0
f0rza created

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.

  1. Have created .edmx, customized T4 templates to inherit generated classes from Abp.Domain.Entities.Entity.
  2. 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)
  • User Avatar
    0
    hikalkan created
    Support Team

    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.

  • User Avatar
    0
    f0rza created

    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 ?

  • User Avatar
    0
    f0rza created

    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.
    
  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    Instead of [NotMapped], use [Column("YourTableId")] to specify Id field.

  • User Avatar
    0
    f0rza created

    Works! Many thanks :)