c# 4.0 - How to convert a procedure into create criteria with nhibernate -
i have stored procedure have convert nhibernate create criteria.i have done mapping related procedure in .hbm file.but when debug code, no data retrieved.but when give same values in procedure in sql server, retrieve data.
i have following stored procedure
create procedure ak_reportdata_glactivityd_beginningbalance @companyid uniqueidentifier, @propertyid uniqueidentifier = null, @startaccount float, @endaccount float, @startdate datetime set nocount on declare @dtzerodate datetime declare @dtfiscalyearstart datetime -- set constants select @dtzerodate = convert(datetime, '1-jan-1900') -- if companyid not supplied propertyid if @companyid null select @companyid = fcompanyid tscproperty fpropertyid = @propertyid --get start date of fiscal year containing passed @startdate select @dtfiscalyearstart = fbegindate tscfiscalperiod ffiscalyear = (select ffiscalyear tscfiscalperiod (@startdate between fbegindate , fenddate) , fcompanyid = @companyid) , fperiod = 1 , fcompanyid = @companyid -- calculate beginning balances select la.faccount, sum(ps.fdebitamount - ps.fcreditamount) beginbalance tscledgeraccount la inner join tglpostsummary ps on (la.faccount = ps.faccount , la.fcompanyid = ps.fcompanyid) la.fcompanyid = @companyid , (la.fpropertyid = @propertyid or @propertyid null) , la.faccount between @startaccount , @endaccount , ps.fpostdate >= (case la.ftype when 'liability' @dtzerodate when 'equity' @dtzerodate when 'asset' @dtzerodate else @dtfiscalyearstart end) , ps.fpostdate < @startdate group la.faccount following .hbm files
first 1 is
<?xml version="1.0" encoding="utf-8"?> <hibernate-mapping assembly="blackopsp2.core" namespace="blackopsp2.core.domain.armodule" xmlns="urn:nhibernate-mapping-2.2"> <class name="tglpostsummary" table="tglpostsummary" lazy="true" > <id name="fcompanyid"> <generator class="guid" /> </id> <property name="faccount"> </property> <property name="fpostdate"> </property> <property name="fcreditamount"> </property> <property name="fdebitamount"> </property> <property name="fdatemodified"> </property> <many-to-one name="ledgeraccount" class="tscledgeraccount" insert="false" update="false"> <column name="fcompanyid" /> <column name="faccount" /> </many-to-one> </class> </hibernate-mapping> second 1 is
<?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping assembly="blackopsp2.core" namespace="blackopsp2.core.domain.armodule" xmlns="urn:nhibernate-mapping-2.2"> <class name="tscledgeraccount" table="tscledgeraccount" lazy="true" > <composite-id> <key-property name="fcompanyid"></key-property> <key-property name="faccount"></key-property> </composite-id> <version name="ftimestamp" generated="always" unsaved-value="null" type="binaryblob"> <column name="ftimestamp" not-null="false" sql-type="timestamp"/> </version> <property name="finactive"> </property> <property name="fpropertyid"> </property> <property name="fprojectid"></property> <property name="fcapital"> </property> <property name="fname"> </property> <property name="ftype"> </property> <property name="fdescription"> </property> <property name="fdeplife"> </property> <bag name="postsummary" inverse="true"> <key> <column name="fcompanyid"/> <column name="faccount"/> </key> <one-to-many class="tglpostsummary"/> </bag> </class> </hibernate-mapping> and in c# have written create criteria query.
var beginingbalance= session.createcriteria<tscledgeraccount>("ledger") .createcriteria("ledger.postsummary", "summary", nhibernate.sqlcommand.jointype.innerjoin) .add(expression.and(expression.eq("ledger.fcompanyid", globalmember.primaryfilter.companyid), expression.eq("ledger.fpropertyid", globalmember.primaryfilter.propertyid))) .add(expression.eq("summary.fdebitamount", startaccount)) .add(expression.eq("summary.fcreditamount", endaccount)) .add(expression.eq("summary.fpostdate", convert.todatetime("2012-01-01"))) .setprojection(projections.projectionlist() .add(projections.groupproperty("summary.faccount"), "faccount") .add(projections.property("summary.faccount"), "faccount")) //.add(projections.property("summary.fdebitamount"), "fdebitamount") //.add(projections.property("summary.fcreditamount"), "fcreditamount")) .setresulttransformer(transformers.aliastobean(typeof(tscledgeraccount))) .list<tscledgeraccount>(); return beginingbalance; please me solve out problem stuck in problem.any appreciated.
thanks
i using c# language , nhibernate.
Comments
Post a Comment