Linq to實(shí)體不識(shí)別方法。在嘗試執(zhí)行Linq查詢時(shí),我得到了以下錯(cuò)誤:Linq to Entites不識(shí)別‘boolealIsCharityMatching(System.String,System.String)’方法,而且此方法無(wú)法轉(zhuǎn)換為存儲(chǔ)表達(dá)式。我已經(jīng)讀過很多以前的問題,人們會(huì)得到同樣的錯(cuò)誤,如果我正確理解,這是因?yàn)長(zhǎng)INQto實(shí)體需要將整個(gè)Linq查詢表達(dá)式轉(zhuǎn)換成服務(wù)器查詢,因此您不能在其中調(diào)用外部方法。我還沒能把我的場(chǎng)景轉(zhuǎn)化成一些有用的東西,我的大腦開始融化,所以我希望有人能給我指明正確的方向。我們使用的是實(shí)體框架和規(guī)范模式(這兩者我都是新手)。下面是使用規(guī)范的代碼:ISpecification<Charity> specification = new CharitySearchSpecification(charityTitle, charityReference);charities = charitiesRepository.
Find(specification).OrderBy(p => p.RegisteredName).ToList();下面是Linq表達(dá)式:public System.Linq.Expressions.Expression<Func<Charity, bool>> IsSatisfied(){
return p => p.IsCharityMatching(this.charityName, this.charityReference);}以下是IsCharityMatching方法:public bool IsCharityMatching(string name, string referenceNumber){
bool exists = true;
if (!String.IsNullOrEmpty(name))
{
if (!this.registeredName.ToLower().Contains(name.ToLower()) &&
!this.alias.ToLower().Contains(name.ToLower()) &&
!this.charityId.ToLower().Contains(name.ToLower()))
{
exists = false;
}
}
if (!String.IsNullOrEmpty(referenceNumber))
{
if (!this.charityReference.ToLower().Contains(referenceNumber.ToLower()))
{
exists = false;
}
}
return exists;}如果你需要更多的信息,請(qǐng)告訴我。非常感謝,安娜莉
Linq to實(shí)體不識(shí)別方法。
慕尼黑5688855
2019-06-18 13:09:19