如何在客户端刷新集合?

发布于 2024-07-21 23:46:16 字数 410 浏览 3 评论 0原文

我从服务器加载客户端数据:

var context = new WordsDomainContext();
context.LoadWords();

并且我根据需要在客户端上使用我的集合context.Words。 运作良好。 但由于某些原因我想刷新我的context.Words。 当我再次调用 context.LoadWords() 时,新记录只需附加到当前集合。

我尝试使用 MergeOption context.LoadWords(null, MergeOption.OverwriteCurrentValues, null) 但没有效果。

如何清理我的 Words 集合并从服务器加载新数据?

I loading data on client from server:

var context = new WordsDomainContext();
context.LoadWords();

And I using my collection context.Words on client as I need. It's working good.
But I want to refresh my context.Words for some reasons. When I call again context.LoadWords() new record just append to current collection.

I tried use MergeOption context.LoadWords(null, MergeOption.OverwriteCurrentValues, null) but no effect.

How I can clean my Words collection and load new data from server?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

许你一世情深 2024-07-28 23:46:17

您可能需要在使用 LoadWords() 之前调用此函数:

context.Refresh(System.Data.Objects.RefreshMode.StoreWins, context.LoadWords);

You probably need to call this before you use the LoadWords():

context.Refresh(System.Data.Objects.RefreshMode.StoreWins, context.LoadWords);
始终不够 2024-07-28 23:46:17

您可以使用以下方法简单地从数据库刷新客户端上的集合:

collection.Load(MergeOption.OverwriteChanges);

顺便说一句 - 集合是 EntityCollection 类型。

You can simply refresh your collection on client from the database using :

collection.Load(MergeOption.OverwriteChanges);

b.t.w - collection is an EntityCollection type.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文