我有一個數據庫調用,返回一個對象。我使用LINQ來施放對象我多麼希望它在Linq查詢中連接字符串
var result = queryResult.OrderBy(c => c.TariffName)
.Take(count)
.Select(c => new
{
Text = c.TariffName,
Key = c.TariffId,
Price = c.LineRental
});
var list = result.ToList();
我現在想的線路租金增加關稅的名字表明它表明這樣的:
myTariff - 12.99
當我嘗試而做這個,雖然我可以做這種變化確定:
Text = c.TariffName + " - ",
但是當我嘗試並添加行租用我得到的LINQ將無法識別問題的ToString()。我需要它看起來像:
Text = c.TariffName + " - " + c.LineRental.ToString(),
據我所知,LINQ不會從閱讀LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression識別ToString()方法,但如何改變這個給我不能將其設置爲前LINQ的字符串查詢?
您可以使用循環來填充結果對象。在循環體中,你可以使用'Text = c.TariffName +「 - 」+ c.LineRental.ToString()' –