gpt4 book ai didi

linq-to-sql - Linq 到 Sql : Can the DataContext instance return collections that include pending changes?

转载 作者:行者123 更新时间:2023-12-04 15:28:19 24 4
gpt4 key购买 nike

考虑以下代码块:

using (PlayersDataContext context = new PlayersDataContext())
{
Console.WriteLine(context.Players.Count()); // will output 'x'
context.Players.InsertOnSubmit(new Player {FirstName = "Vince", LastName = "Young"});
Console.WriteLine(context.Players.Count()); // will also output 'x'; but I'd like to output 'x' + 1
}

鉴于我没有打电话
context.SubmitChanges();

应用程序将在 InsertOnSubmit 语句之前和之后输出相同的玩家计数。

我的两个问题:

Can the DataContext instance return collections that include pending changes?

Or must I reconcile the DataContext instance with context.GetChangeSet()?

最佳答案

当然,使用:

context.GetChangeSet()

为了更细化,有插入、更新和删除的成员。

编辑 : 我现在明白你的新问题了。是的,如果您想在集合中包含更改,则必须以某种方式将 GetChangeSet() 返回的集合与您现有的集合结合起来。

关于linq-to-sql - Linq 到 Sql : Can the DataContext instance return collections that include pending changes?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1261163/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com