c# - NHibernate ICriteria Return Empty Result -


i using nhibernate , creating query below :-

icriteria criteria = session.createcriteria<payinoutbookentry>(); projectionlist projlist = projections.projectionlist();              projlist.add(projections.groupproperty("paymentoption").as("paymentoption"));              criteria.setprojection(projlist);              criteria.setresulttransformer(transformers.aliastobean<payinoutbookentry>());  ilist<payinoutbookentry> payinoutbookentrylist = criteria.list<payinoutbookentry>(); 

poco:

public class payinoutbookentry  {     public virtual int payinoutbookentryid { get; set; }      public virtual methodofpayment paymentoption { get; set; } } 

mapper:

public payinoutbookentrymap()  {         table("payinout_bookentry");         schema("test");         lazy(true);         id(x => x.payinoutbookentryid, map => {             map.column("payinout_bookentry_id");            map.generator(generators.native); });          manytoone(x => x.paymentoption, map =>         {             map.column("payment_option");             //  map.notnullable(true);             map.cascade(cascade.none);         }); 

but when try list 1 row in list , row has empty object.

can please let me wrong groupproperty ? without groupproperty working fine.

the result receiving, correct - in relation query. because icriteria query above end in sql statement:

select this_.payment_option y0_  [test].[payinout_bookentry] this_  group     this_.payment_option 

as can see, group by column in select clause... nothing else selected.

... projectionlist projlist = projections.projectionlist(); // 1 projected select statement projlist.add(projections.groupproperty("paymentoption").as("paymentoption")); // still 1 select result criteria.setprojection(projlist); 

so, if use transformer in next line

// iterates retrieved data , convert them properties criteria.setresulttransformer(transformers.aliastobean<payinoutbookentry>()); 

we still have null everywhere (and default valuetypes) - because that's how works.

so, can change that?

firstly add more columns projections

... projlist.add(projections.count("payinoutbookentryid").as("payinoutbookentryid")); ... 

but in fact, won't make sense, because in id column know have (transformed) count of ids... not want.

that happening, because (i guess) projecting , grouping here used not right way. serves kind of reporting (we create dto , compute how many money, count have per type)

but in case want bookentries related payment.. use where, e.g.:

criteria.add(restrictions               .where<payinoutbookentry>(o => o.paymentoption.id == somepaymentoptiontype)); 

and way can entries, related filtered payment type...

read more it:


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -