Entity Framework throws exception - Invalid object name 'dbo.BaseCs'

后端 未结 12 950
挽巷
挽巷 2020-11-30 11:59

I\'ve followed Adam\'s answer here and the Entity Framework now works and the Seed() method also works.

But when I try to access the database l

12条回答
  •  天涯浪人
    2020-11-30 12:43

    It is most likely a mismatch between the model class name and the table name as mentioned by 'adrift'. Make these the same or use the example below for when you want to keep the model class name different from the table name (that I did for OAuthMembership). Note that the model class name is OAuthMembership whereas the table name is webpages_OAuthMembership.

    Either provide a table attribute to the Model:

    [Table("webpages_OAuthMembership")]
    public class OAuthMembership
    

    OR provide the mapping by overriding DBContext OnModelCreating:

    class webpages_OAuthMembershipEntities : DbContext
    {
        protected override void OnModelCreating( DbModelBuilder modelBuilder )
        {
            var config = modelBuilder.Entity();
            config.ToTable( "webpages_OAuthMembership" );            
        }
        public DbSet OAuthMemberships { get; set; }        
    }
    

提交回复
热议问题