Why mapping is not working using Entity Framework

2019-09-04 17:24发布

I have created a context of Entity Framework like below: using System;

 using System.Data.Entity;
 using System.Data.Entity.ModelConfiguration.Conventions;
 using System.Collections.Generic;
 using System.Linq;
 using System.Web;

 namespace UniversityApp.Models
 {
   public class ProfDb : DbContext
      {

        public DbSet<Professor> Professors { get; set; }
         public DbSet<Student> Students { get; set; }

         }
     }

I am using VS 2015 Professional. Then I go to View=>Server Explorer=> Add Connection=> Microsoft Sql Server => In Data Source I choose (LocalDb)\MSSQLLocalDB , and when I go to select a database name I do not find UniversityApp.Models.ProfDb as an option. I have also created a new object of ProfDb in one of my controller but still not working. Should anyone tell me why mapping is not working in my application and what I should do?

1条回答
仙女界的扛把子
2楼-- · 2019-09-04 17:29

Try this, Go to Web config, search for

 <entity framework>

Add this

<contexts>
 <context type="UniversityApp.Models.ProfDb , UniversityApp">
  <databaseInitializer type="Your SEED , UniversityApp" />
</context>

查看更多
登录 后发表回答