一区二区三区日韩精品-日韩经典一区二区三区-五月激情综合丁香婷婷-欧美精品中文字幕专区

分享

linq to sql 轉(zhuǎn)到linq to entitis幾個(gè)需要修改地方

 實(shí)力決定地位 2013-05-22

  

                   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

    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多

    儿媳妇的诱惑中文字幕| 亚洲中文字幕人妻系列| 欧美日韩国内一区二区| 国产成人精品一区在线观看| 欧美日韩精品一区二区三区不卡| 99久久人妻精品免费一区| 亚洲国产中文字幕在线观看| 黄色片一区二区三区高清| 出差被公高潮久久中文字幕| 亚洲国产欧美久久精品| 不卡中文字幕在线免费看| 国内精品偷拍视频久久| 欧美一区二区三区喷汁尤物| 欧美丰满人妻少妇精品| av中文字幕一区二区三区在线 | 少妇熟女精品一区二区三区| 国产女高清在线看免费观看| 狠狠做深爱婷婷久久综合| 欧美黑人暴力猛交精品| 麻豆果冻传媒一二三区| 五月综合激情婷婷丁香| 成人国产一区二区三区精品麻豆 | 日本高清一道一二三区四五区| 亚洲欧美中文日韩综合| 欧美成人精品一区二区久久| 欧美日韩亚洲精品在线观看| 亚洲欧洲一区二区综合精品| 亚洲永久一区二区三区在线| 亚洲欧洲精品一区二区三区| 日本av在线不卡一区| 在线免费国产一区二区| 老熟女露脸一二三四区| 国产白丝粉嫩av在线免费观看| 免费大片黄在线观看日本| 国产一区二区三区精品免费| 国产午夜福利片在线观看| 人妻露脸一区二区三区| 老司机这里只有精品视频| 久七久精品视频黄色的| 国产一级性生活录像片| 中文字幕一区二区三区大片|