我一直在 ASP.NET MVC3 应用程序中使用代码优先技术。这是非常基本的问题,即如何更新导航属性。以下是详细代码。
public class Destination
{
public int ID {get;set;}
// some other properties
public Country {get;set;}
}
public class Country
{
int ID {get;set;}
string Name {get;set;}
}
//i have simple structure as above. when i go to update destination entity. Country is not getting updated.even i tried following:
_db.Entry(Destination.Country).State = System.Data.EntityState.Modified;
_db.Entry(Destination).State = System.Data.EntityState.Modified;
//_db.ChangeTracker.DetectChanges();
_db.SaveChanges();
其次,当我去添加它工作正常。是否需要明确要求外键关系?