ASP.NETMVC3アプリでコードファーストの手法を使用しています。ここでは、非常に基本的な問題、つまりナビゲーションプロパティを更新する方法があります。以下は詳細なコードです。
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();
第二に、私が追加に行くとき、それはうまくいきます。foriegnKeyの関係を明示的に要求する必要はありますか?