在工作流中序列化 POCO
我只是想知道,我尝试从 MVC 应用程序向我的 WF4 工作流程提供 POCO 对象,它工作得很好,直到我尝试保留它。我正在使用中加载我的对象,当我持久化工作流程时,它告诉我它无法持久化,因为上下文不再存在。谁能告诉我为什么需要 Context 来序列化对象?
获取我的对象包括这样的内容:
public User GetUser(string userName)
{
return (from user in _entities.Users.Include("Values").Include("RoleRelations")
where user.Name == userName
select user).FirstOrDefault();
}
I was just wondering, I tried giving a POCO Object to my WF4 workflow from my MVC Application, which worked just fine until I tried persisting it. I was loading my Object in a Using and when I persisted the workflow, it told me that it can not be persisted because the context does not exist anymore. Can anyone tell me why it needs the Context to serialize an object?
Getting my object with includes like this:
public User GetUser(string userName)
{
return (from user in _entities.Users.Include("Values").Include("RoleRelations")
where user.Name == userName
select user).FirstOrDefault();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果没有上下文,如果您在尝试序列化时不急于加载包含的所有相关数据,它将尝试从上下文中延迟加载它们。如果上下文已被销毁,则 POCO 对象无法完全填充,因此无法干净地序列化。
Without the context if you're not eager loading all relevant data for your includes when you try to serialize it will try to Lazy-load them from the context. If the context has already been destroyed the POCO object cannot be fully populated, and so cannot be cleanly serialized.