I need to combine 2 fields into 1 field. Name and Price.
However, I am getting a LINQ error
LINQ to Entities does not recognize the method ‘System.String ToString
Here is my linq statement.
var results = ctx.Plans.Select(p => new PlansView
{
PlanID = p.planID,
PlanActive = p.planActive,
PlanCost = p.planCost,
PlanName = p.planName,
PlanNameAndCost = p.planName + " " + Convert.ToString(p.planCost)
}).OrderBy(p => p.planName).ToList();
PlanNameAndCost = p.planName + ” ” + Convert.ToString(p.planCost) is causing the error.
I understand that SQL does not have a ToString,
but how can I get this to work?
This is expected: the projection is executed on the RDBMS side; your SQL database has no idea what’s
ToString. This member should be added when you are in memory, i.e. afterAsEnumerable():