kriebb
kriebb

Reputation: 3

Nhibernate Projection Query DTO, use method in stead of property

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...)

Upvotes: 0

Views: 447

Answers (1)

Diego Mijelshon
Diego Mijelshon

Reputation: 52753

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
                                  });

Upvotes: 1

Related Questions