我在网上查了其他代码,但我无法理解refresh()方法的参数来刷新我的linq-to-sql数据上下文。无法理解Refresh()方法刷新LINQ-to-SQL DataContext。
我正在删除表B的数据,以便我可以删除表A的数据。然后我想更新我的Gridview,以便它现在显示表B的数据并删除了所需的记录。
public static void DeleteCategory(int id)
{
var result = from a in adb.Artifacts //adb is my data context visible to every code.
where a.CatgId == id
select new { artid = a.ArtId};
var count = result.Count();
int counter = 0;
if (count > 0)
{
foreach (var r in result)
{
MyArtifact.DeleteByKey(r.artid);
count--;
counter = 1;
}
}
if (counter==0)
{
MyCategories.DeleteByKey(id);
}
//我应该使用刷新()方法,在这里,但我不能够理解的参数RefreshMode和实体!有人可以解释我这两个! }
谢谢
http://blogs.msdn.com/b/dinesh.kulkarni/archive/2008/05/23 /linq-to-sql-tips-6-how-to-refresh-given-datacontext-won-t-stomp-on-your-objects.aspx – 2012-02-28 14:20:02
嘿蒂姆, 我检查过这个博客!但是我无法确定我的应用程序的refresh()参数应该使用什么。它说实体和刷新模式。 谢谢 – 2012-02-28 14:21:52
我试过写过adb.Refresh(RefreshMode.OverwriteCurrentValues,Artifact);但这样做,我得到一个错误“AdlibCoreModel.Artifact”是一个'类型',但像'变量'使用 – 2012-02-28 14:29:11