你能幫忙嗎?我敢打賭,這並不是一件困難的事情。但對於EF來說並不陌生,面臨着週末的最後期限。我想用值更新表格,但主鍵是標識列。所以我的任務是這樣的..如果它存在,更新..如果它不添加到
表..這是我的代碼..並卡在這其他部分..!實體框架更新表4/mvc 3!
表結構是這樣的
主鍵表 - 系統:SYSTEMID,的SystemName
外鍵表 - SystemConfiguration:SystemConfigurationId,SYSTEMID,SystemRAM,SystemHard磁盤
public void SaveSystemConfigurations(SystemConfiguration systemConfig)
{
var config = (from s in Context.SystemConfiguration
where s.SystemId == systemConfig.SystemId
select s).FirstOrDefault();
if (config == null)
{
Context.SystemConfigurations.AddObject(systemConfig);
Context.SaveChanges();
}
else
{
// EntityKey systemConfigKey= new EntityKey("systemConfig", "systemConfigId", config.SystemConfigurationId);
Context.SystemConfigurations.Attach(systemConfig);
Context.SaveChanges();
}
}
智能感知不給任何.Attibute? – hillary 2011-04-11 01:23:33
是的。 。屬性只是一個例子。用您想要更新的屬性替換.Attribute。例如。 config.DateModified = DateTime.Now;等等 – ysrb 2011-04-11 01:28:26
謝謝.. ysrb..this作品像一個魅力..!我正在進一步研究,如果theres更好的解決方案..不是手動設置這麼多列.. – hillary 2011-04-11 02:17:21