In
LINQ -to-EF query, First EF query is translated into SQL and when we are
trying to translate some code into SQL and something is not supported in SQL
and then this exception occurred.
In above EF Query, the function MapToPersonData() is being used to map the person entity into person data object and in this function, we are concatenating of the city and Street string and the concatenating of string will not be supported in LINQ to entties, so the above error is occured.
Other entity framework related links:
"The LINQ
expression node type 'Invoke' is not supported in LINQ to Entities in entity
framework"
public List<PersonData> GetAll()
public List<PersonData> GetAll()
{
return _db.Persons.Select(x
=> MapToPersonData(x)).ToList();
}
internal static Func<Person, PersonData> MapToPersonData = m =>
{
if (m == null)
{
return null;
}
else
{
return new PersonData()
{
PersonID = m.PersonID,
Name = m.Name,
Location = m.Location.City +""+ m.Location.Street
};
}
};
In above EF Query, the function MapToPersonData() is being used to map the person entity into person data object and in this function, we are concatenating of the city and Street string and the concatenating of string will not be supported in LINQ to entties, so the above error is occured.
What solution I found, we have to fetch
data from database table in your local memory by calling
.ToList()/.ToEnumerable() function and then we can apply logic on top of that
similar like LINQ-To-Object
public List<PersonData>
GetAll()
{
return _db.Persons.AsEnumerable().Select(x
=> MapToNameData(x)).ToList();
}
Other entity framework related links:
Thanks for Visiting and please leave your comments, if it helps you.