Hello
I'm quite a beginner with NHibernate but I have run into a problem I
can't seem to come any closer to fix. Is this a bug?
I'm trying to make my self a class that looks like the following:
Code:
public class Price
{
public virtual int PriceId { get; set; }
public virtual int PerQuantityMultiplier { get; set; }
public virtual int Generation { get; set; }
public virtual DateTime EffectiveDate { get; set; }
}
With the following mapping file:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" >
<class name="Volvo.Purchasing.Pricing.DomainModel.Entities.Price,
Entities" >
<id name="PriceId" column="PriceId" type="System.Int32" unsaved-
value="null">
<generator class="native"/>
</id>
<property name="PerQuantityMultiplier" column="Multiplier" not-
null="false" type="System.Int32" insert="true" update="true"/>
<property name="EffectiveDate" column="EffectiveDate" not-
null="true" type="System.DateTime" insert="true" update="true"/>
<property name="Generation" column="Generation" not-null="true"
type="System.Int32" formula="ROW_NUMBER() OVER (PARTITION BY
AgreementId ORDER BY EffectiveDate DESC) " />
</class>
</hibernate-mapping>
When I fetch a list of this class I get an "Can''t execute query
exception". This is because NHibernate prefixes my Formula query and
doesn't seem to recognize the reserved words PARTITION and OVER.
The SQL NHibernate tries to execute as a result of the configuration
(with the formula) is this:
Code:
SELECT this_.PriceId as PriceId0_0_,
this_.Multiplier as Multiplier0_0_,
this_.EffectiveDate as Effectiv3_0_0_,
(ROW_NUMBER() [b]this_.[/b]OVER ([b]this_.[/b]PARTITION BY this_.AgreementId ORDER
BY this_.EffectiveDate DESC)) as formula0_0_
FROM Price this_
I just need to change this to:
Code:
SELECT this_.PriceId as PriceId0_0_,
this_.Multiplier as Multiplier0_0_,
this_.EffectiveDate as Effectiv3_0_0_,
(ROW_NUMBER() OVER (PARTITION BY this_.AgreementId ORDER BY
this_.EffectiveDate DESC)) as formula0_0_
FROM Price this_
Is there anyway to stop NHibernate from being "smart", to tell NHibernate not to do this replacment of my custom SQL query? Or to do some escape sequence for the reserved words?
Or to hook in to the executing of the SQL Query and just do a string replace of what is wrong?
Very, very greatful for any help in this matter.
KR
Robin