RIA:加载实体集
在使用 SL4 RIA 实体时,我遗漏了一些非常基本的东西。 我有一个包含 User
实体的域服务。在服务上下文中,我有一个方法:
EntityQuery
我执行如下加载:
context.Load(context.GetUsersQuery(), (loadOp)=>
{
// Things done when the load is completed
}, null);
当执行 Completed
操作时,loadOp.Entities
集合充满了 User
> 实体,但它们未附加到 context.Users
实体集。我似乎也无法从回调中手动附加它们。为了在实体集中跟踪这些内容,我错过了哪些重要步骤?
只是为了详细说明,在已完成的处理程序中,我尝试了:
foreach (var user in loadOp.Entities)
context.Users.Attach(user);
我收到一个异常,表示已附加具有该名称的实体。 然而,context.Users
和 context.EntityContainer
都是空的。
I am missing something very fundamental when working with SL4 RIA entities.
I have a Domain Service with User
entities. On the service context, I have a method:
EntityQuery<User> GetUsersQuery()
I perform a load like so:
context.Load(context.GetUsersQuery(), (loadOp)=>
{
// Things done when the load is completed
}, null);
When the Completed
action executes, the loadOp.Entities
collection is full of the User
entities, but they are not attached to the context.Users
entity set. It also appears that I can't attach them manually from the callback. What important step am I missing to get these tracked in the entity set?
Just to elaborate, in the completed handler, I tried:
foreach (var user in loadOp.Entities)
context.Users.Attach(user);
And I get an exception that says an entity with that name is already attached.
Yet, both context.Users
and context.EntityContainer
are empty.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您确定在所有情况下都使用相同的上下文实例吗?
context.EntityContainer.GetEntitySet().Count
说什么?LoadOperation.HasError
返回 true 吗?如果是这样,错误是什么?Are you sure you are using the same instance of the context in all cases? What does
context.EntityContainer.GetEntitySet<User>().Count
say?Does
LoadOperation<User>.HasError
return true? If so, what is the error?