我正在努力NHibernate的標準至極,我畢業生根據輸入參數upp。Nhibernate標準有條件的地方
我對這些參數的郵件部分有些問題。 由於我們得到了一個5位數字的郵政編碼,輸入參數是一個整數,但由於我們在數據庫中也接受外國郵編,數據庫將其保存爲字符串。
即時嘗試在NHibernate Criteria/Criterion中複製的內容是以下where子句。
WHERE
11182 <=
(case when this_.SendInformation = 0 AND dbo.IsInteger(this_.Zipcode) = 1 then
CAST(REPLACE(this_.Zipcode, ' ', '') AS int)
when this_.SendInformation = 1 AND dbo.IsInteger(this_.WorkZipcode) = 1 then
CAST(REPLACE(this_.WorkZipcode, ' ', '') AS int)
when this_.SendInformation = 2 AND dbo.IsInteger(this_.InvoiceZipcode) = 1 then
CAST(REPLACE(this_.InvoiceZipcode, ' ', '') AS int)
else
NULL
end)
,我們要做的就是檢查其中的部件接觸(this_
)已preferenced到獲取發送到信息,然後我們檢查輸入郵政編碼爲整數針對三個不同的列取決於列是否可轉化爲int( IsInteger(expr)
功能)如果列不是可轉換我們標記在這種情況下,側NULL
我們只是檢查拉鍊碼是(逆轉SQL代碼因爲放慢參數是第一)> =輸入參數,目標是之間做(用'AND'語句包裹的2個子句),> =或< =。
UPDATE
得到成功的提示。
Projections.SqlProjection("(CASE when SendInformation = 0 AND dbo.IsInteger(Zipcode) = 1 then CAST(REPLACE(Zipcode, ' ', '') AS int) when SendInformation = 1 AND dbo.IsInteger(WorkZipcode) = 1 then CAST(REPLACE(WorkZipcode, ' ', '') AS int) when SendInformation = 2 AND dbo.IsInteger(InvoiceZipcode) = 1 then CAST(REPLACE(InvoiceZipcode, ' ', '') AS int) else NULL END)"
, new[] { "SendInformation", "Zipcode", "WorkZipcode", "InvoiceZipcode" },
new[] { NHibernateUtil.Int32, NHibernateUtil.String, NHibernateUtil.String, NHibernateUtil.String });
把我的整個子句中Projections.SqlProjection,但是當我跑我的代碼我的一些投影被切斷(「AS INT)其他NULL END)」從切成末),使SQL腐敗。 這是否有某種限制?
儘管我不是T-SQL的粉絲,但這可能是使用SQL函數封裝邏輯然後使用公式映射屬性或使用sqlprojection的好例子但調用函數(我不知道在SQL投影中的sql的長度限制) –