gpt4 book ai didi

NHibernate 3.1 忽略计算列公式

转载 作者:行者123 更新时间:2023-12-04 00:54:20 24 4
gpt4 key购买 nike

我有一个带有两个计算列的类。公式是从其他表中获取计数的选择语句,如下所示:

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();
});

对于 Fluent NHibernate 1.1(使用 NHibernate 2.1),这一切都很好,但我刚刚升级到 1.2(使用 NH 3.1),而且 Fluent NHibernate 似乎忽略了这些公式。我收到 HasTakenSurvey 和 Votes 两个字段的“无效列名”异常,因为它试图直接查询列而不是按照指示执行公式。一个示例查询:

exec sp_executesql N'select TOP (@p0) business0_.Id as Id0_, business0_.UserPassword as UserPass2_0_, business0_.HasTakenSurvey as HasTaken3_0_, business0_.Votes as Votes0_, business0_.Origin as Origin0_, business0_.BusinessName as business0_. Business7_0_,business0_.BusinessType 为 Business8_0_,business0_.BusinessImageUrl 为 Business9_0_,business0_.BusinessDescription 为 Busines10_0_,business0_.EmployeeCount 为 Employe11_0_,business0_.OwnerFirstName 为 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 Busines20_0_、business0_.UserBusinessPhone as Busines17_0_、business0_.BusinessState as Busines18_0_、business0_.BusinessCountry as Busines20_0_、business0_.UserBusinessPhone as User_User_Ema_Ema_User_20Phone 作为User_Bus20,MoPhone 作为User_Bus20、UserBusinessPhone as User_Bus20,用户IpAddress as UserIpA24_0_, business0_.OptInReminders as OptInRe25_0_, business0_.OptInOffers as OptInOf26_0_, business0_.OptInSms as OptInSms0_, business0_.Created as Created0_, business0_.Modified from business.Np_Business, business0_。 int',@p0=25

实现有变化吗?我究竟做错了什么?

最佳答案

如评论中所述 ConventionBuilder.Property.Always(x => x.Column(x.Property.Name)) 正在将列添加到所有属性(并覆盖公式)。

将 .Columns.Clear() 添加到映射应该删除该列,因此:

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();
});

关于NHibernate 3.1 忽略计算列公式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5758168/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com