'LINQ to Entities无法识别方法'System.String ToString()'方法,并且此方法无法转换为存储表达式 [英] 'LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression

查看:70
本文介绍了'LINQ to Entities无法识别方法'System.String ToString()'方法,并且此方法无法转换为存储表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于linq查询的以下两种类型我已经尝试过,因为它显示错误

'LINQ to Entities无法识别方法'System.String ToString()'方法,而且这种方法不能被翻译成商店表达



请帮助



The follow two types on linq query i've tried since it is showing error
'LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression

please help

//var data = context.SpotBillOutputData
           //    .Join(context.SpotBillInputData,O=>O.CONS_REF,I=>I.CONS_REF,(O,I)=>new {O,I})
           //   .Join(context.SpotBillInputData, OB => OB.O.BILL_MTH, IB => IB.BILL_MTH.ToString(), (OB, IB) => new { OB, IB })
           //    .Where(c=>c.OB.O.BILL_MTH==MaxBillMonth && c.IB.CSTS_CD=="R" && c.OB.O.SDO_CD==SDO &&c.OB.O.BINDER==Binder)
           //    .Select(c => new Consumer { SDO_CD = c.OB.O.SDO_CD, BINDER = c.OB.O.BINDER, ACC_NO = c.OB.O.ACC_NO, NAME = c.IB.NAME, ADDR1 = c.IB.ADDR1, ADDR2 = c.IB.ADDR2, ADDR3 = c.IB.ADDR3, TRF_CD = c.IB.TRF_CD, CSTS_CD = c.OB.O.CSTS_CD, CONN_LOAD = c.IB.CONN_LOAD, METER_NO = c.IB.METER_NO, OPNRDG = c.IB.OPNRDG, OPNRDGSTS = c.IB.OPNRDGSTS }).ToList<Consumer>();


           var data = (from c in context.SpotBillOutputData
                       join
                           i in context.SpotBillInputData on new { CONS_REF = c.CONS_REF, BILL_MTH = c.BILL_MTH } equals new { CONS_REF = i.CONS_REF, BILL_MTH = Convert.ToString(i.BILL_MTH) }

                       where c.CSTS_CD == "R" && c.SDO_CD == SDO && c.BINDER == Binder && c.BILL_MTH == MaxBillMonth

                       select new Consumer { SDO_CD = c.SDO_CD, BINDER = c.BINDER, ACC_NO = c.ACC_NO, NAME = i.NAME, ADDR1 = i.ADDR1, ADDR2 = i.ADDR2, ADDR3 = i.ADDR3, TRF_CD = i.TRF_CD, CSTS_CD = c.CSTS_CD, CONN_LOAD = i.CONN_LOAD, METER_NO = i.METER_NO, OPNRDG = i.OPNRDG, OPNRDGSTS = i.OPNRDGSTS }).ToList<Consumer>();

推荐答案

错误消息告诉您问题,基本上您无法在链接中执行Convert.ToString(i.Bill_MTH)调用。在不了解您的数据结构的情况下,很难建议解决方案,但我建议您查看为什么需要将其转换为字符串,看看是否可以避免我的匹配数据类型。
The error message tells you the problem, basically you cannot do your "Convert.ToString(i.Bill_MTH)" call within your link. Without knowing anything about your data structures it is hard to advise a solution, but I would suggest you look at why you need to convert it to a string and see if that can be avoided my matching data types.


这篇关于'LINQ to Entities无法识别方法'System.String ToString()'方法,并且此方法无法转换为存储表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆