2011-09-27 47 views
0

我有3個表數據庫:錯誤與實體框架4和MVC 3

  • 主題
  • 成員
  • 主題

然後,我添加了連接字符串web.config和創建具有以下類別的EF:

namespace MySite.Models 
{ 
    public class MySiteDBModel : DbContext 
    { 
     public DbSet<Topic> Topics { get; set; } 
     public DbSet<Subject> Subjects { get; set; } 
     public DbSet<Member> Members { get; set; } 
     public DbSet<TopicDataModel> TopicDataModel { get; set; } 
     protected override void OnModelCreating(DbModelBuilder mb) 
     { 
      mb.Conventions.Remove<PluralizingTableNameConvention>();    
     } 
    } 

    public class Topic 
    { 
     [Key] 
     public int TopicID { get; set; } 
     public int SubID { get; set; } 
     public int MemberID { get; set; } 
     public string TDate { get; set; } 
     public string Title { get; set; } 
     public string FileName { get; set; } 
     public int Displays { get; set; } 
     public string Description { get; set; } 
     public virtual Subject Subject { get; set; } 
     public virtual Member Member { get; set; } 
     public virtual ICollection<TopicView> TopicView { get; set; } 
    } 
    public class Subject 
    { 
     [Key] 
     public int SubID { get; set; } 
     public string SubName { get; set; } 
     public virtual ICollection<Topic> Topic { get; set; } 
    } 

    public class Member 
    { 
     [Key] 
     public int MemberID { get; set; } 
     public string FLName { get; set; } 
     public string Email { get; set; } 
     public string Pwd { get; set; } 
     public string About { get; set; } 
     public string Photo { get; set; } 
     public virtual ICollection<Topic> Topic { get; set; } 
    } 

    public class TopicDataModel 
    { 
     [Key] 
     public int TopicID { get; set; } 
     public string SubName { get; set; } 
     public string FLName { get; set; } 
     public string TDate { get; set; } 
     public string Title { get; set; } 
     public int Displays { get; set; } 
     public string Description { get; set; } 
    } 
} 

現在,當我試圖查詢與此代碼數據庫:

public ActionResult Index() 
     { 
      var topics = from t in db.Topics 
         join s in db.Subjects on t.SubID equals s.SubID 
         join m in db.Members on t.MemberID equals m.MemberID 
         select new TopicDataModel() 
         { 
          TopicID = t.TopicID, 
          SubName = s.SubName, 
          FLName = m.FLName, 
          TDate = t.TDate, 
          Title = t.Title, 
          Displays = t.Displays, 
          Description = t.Description 
         }; 
      return View(topics.ToList()); 
     } 

我得到這個錯誤:

The model backing the 'MySiteDBModel' context has changed since the database was created. Either manually delete/update the database, or call Database.SetInitializer with an IDatabaseInitializer instance. For example, the DropCreateDatabaseIfModelChanges strategy will automatically delete and recreate the database, and optionally seed it with new data.

請幫我!!!!!!

回答