Click here to Skip to main content
15,897,163 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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

C#
//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>();
Posted

1 solution

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.
 
Share this answer
 
Comments
Bikash Prakash Dash 12-Aug-14 5:09am    
actually i.Bill_MTH in decimal but o.Bill_MTH is a string type

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900