Consider this:
var query = (from u in entity.Users
select new
{
FullName = u.FirstName + " " + u.LastName
}
);
Which works fine, but what I want to do is this:
var query = (from u in entity.Users
select new
{
FullName = u.FullName
}
);
I am using Metadata which returns (u.FirstName + " " + u.LastName)
[NotMapped]
public string FullName
{
get
{
return FirstName + " " + LastName;
}
}
But I am getting an error:
The specified type member 'FullName' is not supported in LINQ to Entities.
I know that if I materialize the query it will work fine but I don’t want to do that. I want to do it at the db level, so what’s the best way of doing it, is it possible? Or I have to do this (u.FirstName + " " + u.LastName)
all the time
p.s: I've also tried this: (not working for me)
public static Expression<Func<User, string>> FullName()
{
return u => u.FirstName + " " + u.LastName;
}
Thank you