2
嗨,我在我的代碼中遇到問題。無法更新數據庫實體
public static void settingSoundxStringLawyers_info()
{
mydatabaseEntities db2 = new mydatabaseEntities();
var UniqueNameObjects = from a in db2.Lawyers_info
group a by a.Name into g
where g.Count()==1
select new Names { Name = g.Key };
List<Names> list = UniqueNameObjects.ToList();
for (int i=0; i<150 ; i++)
{
string name = list.ElementAt(i).Name;
Lawyers_info obj = db2.Lawyers_info.Where(l => l.Name == name).First();
string scode = soundxmethod(obj.Name);
obj.SoundxString = scode;
db2.Entry(obj).State = EntityState.Modified;
//var dbEntityEntry = db2.Entry(obj);
//dbEntityEntry.Property(s=>s.SoundxString).IsModified = true;
Console.WriteLine("Index: ----> "+(i+1));
//db2.Lawyers_info.Add(obj);
//db2.Set(Lawyers_info).SqlQuery("update Lawyers_info values(SoundxString = @p)",new sq)
db2.SaveChanges();
}
db2.SaveChanges();
}
我試過每個註釋行但不是woking。更改不會保存在數據庫中。