NHibernate 3.1 ignores computed column formula

I have a class with two computed columns. Formulas are selection commands that capture the number of samples from other tables, for example:

private const string VOTES_FORMULA = "(select count(v.id) from Votes v where v.BusinessID = Id)"; private const string SURVEY_FORMULA = "(select cast((case when exists (select * from surveys s where s.businessid = Id) then 1 else 0 end) as bit))"; // in my bootstrap code... mappings.Override<Business>(map => { map.IgnoreProperty(x => x.IsNewRecord); map.IgnoreProperty(x => x.IdString); map.Map(x => x.UserPassword).CustomType<EncryptedStringType>(); map.Map(x => x.HasTakenSurvey).Formula(SURVEY_FORMULA).Not.Insert().Not.Update(); map.Map(x => x.Votes).Formula(VOTES_FORMULA).Not.Insert().Not.Update(); }); 

This all worked fine with Fluent NHibernate 1.1 (using NHibernate 2.1), but I just upgraded to 1.2 (using NH 3.1), and it seems Fluent NHibernate is ignoring the formulas. I get an "invalid column name" exception for the two fields HasTakenSurvey and Votes, because it "is trying to directly query the columns and not execute the formulas as directed. Example request:

exec sp_executesql N'select TOP (@ p0) business0_.Id as Id0_, business0_.UserPassword as UserPass2_0_, business0_.HasTakenSurvey as HasTaken3_0_, business0_. Log in as Votes0_, business0_.Origin as Origin0__business_.Security_0 business_.Security_0 business_.Security Business7_0_, business0_.BusinessType as Business8_0_, business0_.BusinessImageUrl as Business9_0_, business0_.BusinessDescription as Busines10_0_, business0_.EmployeeCount as Employe11_0_, business0_.OwnerFirstName_user_0L0_0_0O0_0_0O0_0O0_0O0_0O0_0O0_0O0_0O0_0O0_0O0_0O0_0O0_0O0_0O0_0O0_0O0_0_0O0_0O0_0O0_0O0_0_0O0_0_0_0O0_0_0O0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0_0O0_0_0 with If OwnerFi12_0_, business0_. business0_.BusinessAddress2 as Busines16_0_, business0_.BusinessCity as Busines17_0_, business0_.BusinessState as Busines18_0_, business0_.BusinessPostal as Busines19_0_, business0_.BusinessCountry as Busines20_0_, business0_.UserBusinessPhone as UserBus21_22M _0_, business0_.UserEmailAddress as UserEma23_0_, business0_.U serIpAddress as UserIpA24_0_, business0_.OptInReminders as OptInRe25_0_, business0_.OptInOffers as OptInOf26_0_, business0_.OptInSms as OptInS_0_0_0_Of_0_0_0Of_0b0_.OptIn_ms_0_0_0Of_0_0O.jpg by business0_.BusinessName asc ', N' @ p0 INT ", @ p0 = 25

Is the implementation changed? What am I doing wrong?

+4
source share
1 answer

As noted in the comments of ConventionBuilder.Property.Always (x => x.Column (x.Property.Name)) added a column to all properties (and overriding the formula).

Adding .Columns.Clear () to the display should remove the column, therefore:

 mappings.Override<Business>(map => { map.IgnoreProperty(x => x.IsNewRecord); map.IgnoreProperty(x => x.IdString); map.Map(x => x.UserPassword).CustomType<EncryptedStringType>(); map.Map(x => x.HasTakenSurvey).Formula(SURVEY_FORMULA).Not.Insert().Not.Update().Columns.Clear(); map.Map(x => x.Votes).Formula(VOTES_FORMULA).Not.Insert().Not.Update().Columns.Clear(); }); 
+2
source

All Articles