c# - NHibernate LINQ projection using helper class -
i'm trying add projection nhibernate linq query (via .select()), since have bit of logic want use helper class rather returning projected model directly.
my code looks (shortened):
var query = session.query<messageinstance>(); ... (a few .fetch , .thenfetch calls) var result = query.where(specification.issatisfiedby()) .orderby(m => m.creationdate) .select(m => _messagemodelhelper.buildmessagemodel(m)); _messagemodelhelper object transforms messageinstance object messagemodel , contains logic handle different scenarios, since depends on related entities.
this fails error:
field dal.repositories.messagerepository._messagemodelhelper' not defined type 'nhibernate.linq.nhqueryable`1 [domain.entities.message]'
if avoid using field (which necessary di), , this:
.select(m => new messagemodelhelper().buildmessagemodel(m)) i system.notsupportedexception.
it appears approach won't work. can do, while avoiding need return new messagemodel directly? need keep projection, can't operate on enumerable.
you have call buildmessagemodel() "locally":
var result = query.where(specification.issatisfiedby()) .orderby(m => m.creationdate) .asenumerable() // point onward query // executed c#-side .select(m => _messagemodelhelper.buildmessagemodel(m)); note that, written, won't sql projection, full object selected db.
Comments
Post a Comment