Nhibernate Projection Query DTO,使用方法代替属性

发布于 2024-09-12 23:46:23 字数 1557 浏览 4 评论 0原文

这行得通:

    projections.Add(Projections.Property(Member<MailOrder>.From(x => x.AssigneeCode).QualifiedPath), Member<MailOrderItem>.From(x => x.AssigneeCode).Path);
    projections.Add(Projections.Property(Member<MailOrder>.From(x => x.AssigneeName).QualifiedPath), Member<MailOrderItem>.From(x => x.AssigneeName).Path);
    projections.Add(Projections.Property(Member<MailOrder>.From(x => x.AssigneeType).QualifiedPath), Member<MailOrderItem>.From(x => x.AssigneeType).Path);            

这当然行不通

projections.Add(Projections.Property(Member<IMailOrderAssignee>.From(x => x.AssigneeCode).QualifiedPath), Member<MailOrderItem>.From(x => x.Code).Path);
projections.Add(Projections.Property(Member<IMailOrderAssignee>.From(x => x.AssigneeName).QualifiedPath), Member<MailOrderItem>.From(x => x.GetName()).Path);
projections.Add(Projections.Property(Member<IMailOrderAssignee>.From(x => x.AssigneeType).QualifiedPath), Member<MailOrderItem>.From(x => x.GetType()).Path);            

这行不通,因为有两件事:

  1. 接口没有持久化
  2. 方法以属性方式使用。

我在Nhiberante的世界里搜索了很多,但在我看来,这相当困难。

IMailOrderAssignee 是两个根实体(我们称它们为 RootX 和 RootY)的接口。在我的邮购的上下文中,根是什么并不重要,只要我有对它的引用+名称及其代码和电子邮件地址即可。

IMailOrderAssignee 与映射文件中的any - 标记进行映射。 (这很有效,但我也可以用鉴别器来做到这一点)。

我的问题:

  1. 是否可以使用结果 投影查询中的方法的 结果在 DTO 中?

  2. 是否可以使用合约 在投影查询中(我猜 不是...)

This works:

    projections.Add(Projections.Property(Member<MailOrder>.From(x => x.AssigneeCode).QualifiedPath), Member<MailOrderItem>.From(x => x.AssigneeCode).Path);
    projections.Add(Projections.Property(Member<MailOrder>.From(x => x.AssigneeName).QualifiedPath), Member<MailOrderItem>.From(x => x.AssigneeName).Path);
    projections.Add(Projections.Property(Member<MailOrder>.From(x => x.AssigneeType).QualifiedPath), Member<MailOrderItem>.From(x => x.AssigneeType).Path);            

This does not off course

projections.Add(Projections.Property(Member<IMailOrderAssignee>.From(x => x.AssigneeCode).QualifiedPath), Member<MailOrderItem>.From(x => x.Code).Path);
projections.Add(Projections.Property(Member<IMailOrderAssignee>.From(x => x.AssigneeName).QualifiedPath), Member<MailOrderItem>.From(x => x.GetName()).Path);
projections.Add(Projections.Property(Member<IMailOrderAssignee>.From(x => x.AssigneeType).QualifiedPath), Member<MailOrderItem>.From(x => x.GetType()).Path);            

This does not work because of two things:

  1. there is no persister for theinterface
  2. Methods are used in Property way.

I've searched a lot in the world of Nhiberante, but it seems to me that this is quite difficult.

The IMailOrderAssignee is an interface for two rootentity's (let's call them RootX and RootY). In the context of my MailOrders, it isn't important what root it is, as long as I have a reference to it + The Name and it's code and emailaddresses.

The IMailOrderAssignee is mapped with the any - tag in the mapping file. (that works brilliant, but I could do it with an discriminator also).

My question:

  1. Is it possible to use the result
    of a method in a projection query so
    the result is in the DTO?

  2. Is it possible to uses contracts
    in projection querys (I guess
    not...)

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

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

发布评论

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

评论(1

网白 2024-09-19 23:46:23

为什么不在内存中进行投影呢?

例子:

var criteria = someCriteriaThatReturnsPersistentEntities;
var items = criteria.List<IMailOrderAssignee>();
var projected = items.Select(i => new
                                  {
                                      Prop1 = i.SomeMethod(),
                                      Etc
                                  });

Why not do the projection in memory?

Example:

var criteria = someCriteriaThatReturnsPersistentEntities;
var items = criteria.List<IMailOrderAssignee>();
var projected = items.Select(i => new
                                  {
                                      Prop1 = i.SomeMethod(),
                                      Etc
                                  });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文