Linq to sql linq to entits兼容orcle時(shí)所遇相關(guān)問(wèn)題 1LINQ to Entities 不支持 LINQ 表達(dá)式節(jié)點(diǎn)類型“Invoke”
原始代碼:var filter = Queryable.Where(wd.WOO_PROJECT, predicate);
更改后代碼var filter = wd.WOO_PROJECT.Where(predicate.Compile());
2.LINQ to Entities 不識(shí)別方法“Int32 ToInt32(System.String)”,因此該方法無(wú)法轉(zhuǎn)換為存儲(chǔ)表達(dá)式。
通常原始代碼如下:
Where id=Convert.ToInt32(cousid)
更改后代碼:
Var currentid= Convert.ToInt32(cousid);
Wehre id=currentid;
3 LINQ to Entities 不支持 LINQ 表達(dá)式節(jié)點(diǎn)類型“ArrayIndex”。
int[] idArray = BaseExtensions.StrArrayToIntArray(BaseExtensions.StrToStrArray(ids));
int count = wd.WOO_COMP_ATTACHMENT.Count(h => h.CATEGORY_ID == idArray[i]);
執(zhí)行到第二個(gè)語(yǔ)句就報(bào)上門錯(cuò)誤。解決辦法
將帶索引的對(duì)象賦值給一個(gè)變量,在進(jìn)行比較即可
int[] idArray = BaseExtensions.StrArrayToIntArray(BaseExtensions.StrToStrArray(ids));
var id= idArray[i];
int count = wd.WOO_COMP_ATTACHMENT.Count(h => h.CATEGORY_ID ==id);
4.sql方法轉(zhuǎn)化orcle
SqlMethods.DateDiffDay(customer.EXPIRATION_DATETIME.Value, DateTime.Now)), //逾期
上面計(jì)算相差天數(shù)。但是只支持sql server
改成:
System.Data.Objects.EntityFunctions.DiffDays(customer.EXPIRATION_DATETIME.Value, DateTime.Now)
5.假如在一個(gè)query執(zhí)行中提示無(wú)法識(shí)別我們自定義的一個(gè)方法。那就去掉那個(gè)方法。先toList()
然后把list的結(jié)果集作為查詢庫(kù)。然后再調(diào)用那個(gè)方法
比如下面這種寫法
public string GetContractAttachmentCategories() { try { WCMSDATA wd = DataEntity.Initializes(); var query1 = from f in wd.WOO_CATEGORY where f.TYPE == "CONTRACTFILE" select new { LbID = f.ID, LbName = f.NAME, LBPermission = f.ID }; query1 = query1.OrderByDescending(a=>a.LbID); var lis = query1.ToList(); var query = from f in lis select new { LbID = f.LbID, LbName = f.LbName, LBPermission =GetCategoryPermissionUser(f.LBPermission) }; string JsonSource = query.ToJSON(); //當(dāng)前頁(yè)記錄轉(zhuǎn)成JSON格式 string strJsonSource = @"{"; strJsonSource = strJsonSource + @"""fileCategoryList"":" + JsonSource + "}"; return strJsonSource; } catch (Exception e) { WooLogger.Error(e.ToString()); return string.Empty; } }
上面的GetCategoryPermissionUser這個(gè)方法如果放到toList()之前就會(huì)報(bào)無(wú)法識(shí)別此方法。
6 G.Sum(p => p.WOO_CONT_ACTUAL_FINANCE.STATE == "已確認(rèn)" ? p.AMOUNT_MONEY : 0)執(zhí)行錯(cuò)誤
會(huì)提示內(nèi)部執(zhí)行錯(cuò)誤什么的。那就必須改寫
G.Where(p => p.WOO_CONT_ACTUAL_FINANCE.STATE == "已確認(rèn)").Sum(p=> p.AMOUNT_MONEY)
7 join報(bào)錯(cuò)
var customer = wd.WOO_COMPANY.Where(GetAdvancedCustomerSearch().Compile()); //Queryable.Where(wd.WOO_COMPANY, GetAdvancedCustomerSearch()); //var pcfIdsByCustomer = (from pln in wd.WOO_CONT_PLAN_FINANCE // join cust in customer on pln.WOO_CONTRACT.COMPANY_ID equals cust.ID // where pln.TYPE == "收款" // select pln.ID).ToList(); //包含客戶條件的計(jì)劃收款IDs
支持這種寫法
改成如下寫法
var pcfIdsByCustomer = (from cust in customer from pln in wd.WOO_CONT_PLAN_FINANCE where pln.TYPE == "收款" && pln.WOO_CONTRACT.COMPANY_ID == cust.ID select pln.ID).ToList();
問(wèn)題 :System.NotSupportedException: LINQ to Entities 僅支持無(wú)參數(shù)構(gòu)造函數(shù)和初始值
varsList = wd.WOO_CONT_TEXT_TEMP_VALUE.Where(p => p.IS_CUSTOMER == 0) .OrderByDescending(p => p.ID) .Select(p => new TplContractVariable { VarName = p.ID.ToString(), VarLabel = TemplateAndObjectField.GetFildNameByKey(p.NAME, I18NTypeEnum.enUS) }).ToList<TplContractVariable>();
解決
varsList = wd.WOO_CONT_TEXT_TEMP_VALUE.Where(p => p.IS_CUSTOMER == 0) .OrderByDescending(p => p.ID) .Select(p => new { p.ID, p.NAME }) .Select(p => new TplContractVariable { VarName = p.ID.ToString(), VarLabel = TemplateAndObjectField.GetFildNameByKey(p.NAME, I18NTypeEnum.enUS) }).ToList<TplContractVariable>();
無(wú)法創(chuàng)建“WooDataEntity.WOO_PROJECT”類型的常量值。此上下文僅支持基元類型或枚舉類型。 var filter = wd.WOO_PROJECT.Where(predicate.Compile()); var query= from ht in wd.WOO_CONTRACT join xm in filter on ht.PROJECT_ID equals xm.ID where ht.COMPANY_ID == customerID 解決方法:調(diào)換一下位置 var filter = wd.WOO_PROJECT.Where(predicate.Compile()); var query= from xm in filter join ht in wd.WOO_CONTRACT on xm.ID equals ht.PROJECT_ID where ht.COMPANY_ID == customerID |
|
來(lái)自: 實(shí)力決定地位 > 《linq》