[英]LINQ to Entities does not recognize the method 'Int32 ToInt32(System.String)' method
[英]LINQ to Entities does not recognize the method 'Int32 CompareTo(System.String)' method
我想在我的sql查詢中比較2個字符串。 在此查詢中,我希望所有值都大於特定值。 因此,在SQL中,這看起來像是where STREET > 'street'
。 在linq中,我在where子句中使用了它: x => x.Street.CompareTo(_opsm.Street) <= 0
。 但是,當我運行此命令時,我收到一條錯誤消息:
“ LINQ to Entities無法識別'Int32 CompareTo(System.String)'方法,並且該方法無法轉換為商店表達式。”
這是否意味着我無法在EF中使用此比較器?
編輯:我們在我的where查詢中使用規范系統 。 我以前從未遇到過類似的問題,但是仔細檢查,可能與它們有關。
一個簡單規范的示例是這樣的:
var tempspec = new AdHocSpecification<Eenheid>(
x => string.Compare(x.Street, OverzichtPersonenSearch.Street, StringComparison.Ordinal) >= 0
);
這個AdHocSpecification基本上立即返回Expression>(AdHocSpec的代碼在這里 )
足夠奇怪的是:
Een = (from ver in q1
.Where(
x =>
x.PersoonsID == persoon.ComputerNr)
join een in PagedView.Context.EENHEID
on ver.Eenheid equals een.ComputerNr into h
from een in h.DefaultIfEmpty()
select een
).FirstOrDefault(x => string.Compare(x.Street, "02", StringComparison.Ordinal) >= 0)
但這不是:
Een = (from ver in q1
.Where(
x =>
x.PersoonsID == persoon.ComputerNr)
join een in PagedView.Context.EENHEID
on ver.Eenheid equals een.ComputerNr into h
from een in h.DefaultIfEmpty()
select een
).FirstOrDefault(tempspec.IsSatisfied())
EF將查詢轉換為SQL,並且只能轉換其明確支持的函數調用,顯然不支持Int32 CompareTo(System.String)
。
支持使用靜態方法string.Compare(string, string)
: string.Compare(x.Street, _opsm.Street) <= 0
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.