c# - nhibernate criteria set the alias of a subclass parent? -
i have abstract base class contains property called "datecreated"; has number of child classes, of link each other.
when try query against 1 of child classes, ambiguous column error datecreated, contained in more 1 table.
here snippet of criteria:
.setprojection(projections.projectionlist() .add(projections.groupproperty(item.linkfield + ".id"), "measure") .add(projections.count("id"), "statcount") .add(projections.groupproperty("lnk." + item.linktextfield), "measuretext") .add(projections.sqlgroupprojection("month(datecreated) [period]", "month(datecreated)", new[] { "period" }, new itype[] { nhibernateutil.int32 })))
is there way me specify part of criteria alias join between subclass , parent? don't think createalias
work there no joining properties.
if prefix
{alias}.
datecreated
, prefix_this
in generated sql , while alias of current table, not alias of parent table containsdatecreated
field, column not found.if prefix
this_1_.
datecreated
alias nhibernate gives parent table in generated sql, query works, think bad idea.
here generated sql nhibernate:
select top (5) this_.incidenttype_id y0_, count(this_.module_id) y1_, lnk1_.dicttext y2_, month(this_1_.datecreated) [statfrequency] tblincident this_ inner join tblmodule this_1_ on this_.module_id = this_1_.id inner join tbldict lnk1_ on this_.incidenttype_id = lnk1_.id left outer join tbldictcode lnk1_1_ on lnk1_.id = lnk1_1_.dict_id left outer join tbldictimage lnk1_2_ on lnk1_.id = lnk1_2_.dict_id left outer join tbldictsdscategory lnk1_3_ on lnk1_.id = lnk1_3_.dictimage_id this_1_.customer_id = 2 , this_1_.isarchive = 0 , this_1_.isactive = 1 , this_1_.isconfidential = 0 , this_.incidentdate between '2012/01/01' , '2013/04/01' , this_1_.isactive = 1 , this_1_.customer_id = 2 , this_1_.orgunit_id between 3 , 1000 group this_.incidenttype_id, lnk1_.dicttext, month(this_1_.datecreated)
in example, tblincident subclass of tblmodule datecreated contained within tblmodule reason above criteria worked because passed in "this_1_" whats automatically assigned nhibernate. using "{alias}" output "this_1" cause error.
i want way specify alias.
Comments
Post a Comment