Why mapping is not working using Entity Framework in visual studio 2015 professional

天大地大妈咪最大 提交于 2019-12-02 12:18:22

问题


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:


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>



来源:https://stackoverflow.com/questions/41533226/why-mapping-is-not-working-using-entity-framework-in-visual-studio-2015-professi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!