linq to sql toString() 问题
(from c in myIdLeft
join p in context.ConfigurationTree on c.RELAPOINTID equals p.Ct_Node_Id
into bs
from bb in bs.DefaultIfEmpty()
select new { c.ID, c.INSTRCODE, deviceName = bb.Ct_Node_Name == null ? "无" : bb.Ct_Node_Name,
DCBIASVOLTAGE= c.DCBIASVOLTAGE.ToString("0.00"), //这句有问题
c.CreateDate }).ToList();
错误信息:
LINQ to Entities does not recognize the method 'System.String ToString(System.String)' method, and this method cannot be translated into a store expression.
实在没办法了 大伙给点提示呗~~
------解决方案--------------------(from c in myIdLeft join p in context.ConfigurationTree
on c.RELAPOINTID equals p.Ct_Node_Id
into bs from bb in bs.DefaultIfEmpty()
select new { c.ID, c.INSTRCODE,
deviceName = bb.Ct_Node_Name == null ? "无" : bb.Ct_Node_Name,
DCBIASVOLTAGE= c.DCBIASVOLTAGE,
c.CreateDate }).ToList().select(p=> new {
p.ID, p.INSTRCODE,
p.deviceName
DCBIASVOLTAGE= p.DCBIASVOLTAGE.ToString("0.00"),
p.CreateDate
}).ToList();
------解决方案--------------------EF4或者以上 可以使用SqlFunctions.StringConvert
var items = from c in contacts
select new ListItem
{
Value = SqlFunctions.StringConvert((double)c.ContactId).Trim(),
Text = c.Name
};
来自:
http://stackoverflow.com/questions/1066760/problem-with-converting-int-to-string-in-linq-to-entities