如何使用 nhibernate 获取 DTO 成员的集合?
我需要获取填充在 DTO 中的集合属性,但我无法找到有关执行此操作的任何信息。
我尝试这样做:
ICriteria selectCriteria = Session.CreateCriteria<DataRun>()
.SetProjection(Projections.ProjectionList()
.Add(Projections.Property("SomeCollection"), "Collection"))
.SetResultTransformer(Transformers.AliasToBean<MyDto>());
但 MyDto.Collection 始终为空。 我做错了吗,这可能吗?
另外,我最初计划使用子查询来完成此操作,这样我就可以用其他 DTO 填充我的 DTO 集合,但这不起作用,因为子查询的结果超过 1 行(理应如此),而 Sqlit 不喜欢这样(抛出异常)。 在这里做什么是正确的?
I need to get a collection property populated in a DTO and I'm having trouble finding any information on doing this.
I tried to do it like this:
ICriteria selectCriteria = Session.CreateCriteria<DataRun>()
.SetProjection(Projections.ProjectionList()
.Add(Projections.Property("SomeCollection"), "Collection"))
.SetResultTransformer(Transformers.AliasToBean<MyDto>());
but MyDto.Collection is always null. Am I doing this wrong, is this even possible?
Also, I had originally planned on doing this with a SubQuery so I could just fill my DTO's collection with other DTOs but this will not work because the result of the subquery has more than 1 row (as it should) and Sqlit does not like that (throws an exception). what is the right thing to do here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我使用以下语法在项目中检索了集合属性:
其中 id 是父对象的键。
I've retrieved collection properties in my project with the following syntax:
where id is the key of the parent object.
您可以使用自定义转换。
这是您的自定义变压器实现
You may use custom transformation.
Here is your custom transformer implementation