I am getting an exception when I execute this code:
var result = from menu in menuBus.GetMenus()
orderby menu.InternalName
select new
{
Value = menu.ID.ToString(),
Text = menu.InternalName
};
var result = allMenus.ToList();
The error message says: LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a stored expression.
So, I guess that something goes wrong with Value = menu.ID.ToString(). The ID property is defined as GUID (UniqueIdentifier in MS SQL).
Does anybody have a solution for this?
Thank you very much!!!
You need to run the list through another query after querying the database.
var result = (from menu in menuBus.GetMenus()
orderby menu.InternalName
select new
{
Value = menu.ID,
Text = menu.InternalName
}).ToList();
var result2 = (from menu in result select new {Value=menu.Value.ToString(),Text=menu.Text}).ToList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With