The way I do this is through a Computed Column
as explained here:
How to make a computed column nullable in SQL Server
If you use a computed column you'll be able to use such a column in your LINQ queries. For example:
var users = Database.Users.Where(u => u.FullName.ToLower().Contains("string"));
You won't get errors like "not supported in LINQ to Entities" because this property is really a part of your model object. All the heavy lifting occurs on the database side.
Of course you could place a FullName
property in a partial class and use it.
public string FullName
{
get { return string.Format("{0} {1}", FirstName, LastName); }
}
In this case, you'll have to call .ToList()
first ( Database.Users.ToList();
) to be able to use this property in LINQ queries. .ToList()
will hydrate/bring all your Users
to memory. This is not desirable!
You can also try the FullName
property implementation that's described here: Calculated Columns in Entity Framework Code First Migrations