在 LlblGenPro 中合并实体的标准方法
我从带有主键 A1 的实体 A 开始,它有子集合 B 和 C,但它们是空的,因为我没有预取它们。 我现在得到一个新出现的 A(A 素数),主键为 A1,子集合 B 和 C 已填充。
有什么好方法可以让 A 和 A 素数成为同一个对象并填充 B 和 C 的 A 集合?
I start with an entity A with primary key A1, it has child collections B and C, but they are empty, because I haven't prefetched them. I now get a new occurrence of A (A prime) with primary key A1 with the child collections B and C filled.
What is a good way to get the A and A prime to be the same object and to get A collections of B and C filled?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一旦内存中有 2 个独立的对象,并且对它们都有引用,合并它们的唯一方法就是将所有引用更改为指向其中一个对象,这可能是不可能的。 但是,您可以采取一些措施来避免出现这种情况,您可以使用 SD.LLBLGen.Pro.ORMSupportClasses.Context 类,您可以将其附加到适配器并充当缓存层,并且当实体加载后,它会为唯一实体返回相同的对象,基本上它不允许您在内存中复制实体,并且始终返回对已加载实体的引用。
Once you, have 2 separate objects in memory and you have references to both of them the only way to merge them is to change all references to point to one of the objects, which might be impossible. However there's something you can do not to arrive in this situation you can use a SD.LLBLGen.Pro.ORMSupportClasses.Context class which you can attach to an adapter and which acts as a caching layer and when entities are loaded it returns the same object for a unique entity, basically it does't let you duplicate entities in memory and always returns the reference to a already loaded entity.