I have the following class:
public class Contact
{
public int ContactID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}
And the following data:
- 1 / John / Doe
- 2 / Mike / Tyson
- 3 / John / Mc Enroe
- 4 / Stef / Doe
Now I need to let the user search for contacts like this:
John Doe
> get all contacts having the firstnameJohn
and the lastnameDoe
John
> get all contacts having the first nameJohn
Doe
> get all contacts having the last nameDoe
- ...
I tried to add a NotMapped
element to my class and perform my search on this (full) name but LINQ query does not work with NotMapped
elements.
[NotMapped]
public string Name {
get {
return FirstName + " " + LastName;
}
}
var someone = "John Doe";
requests.Where(s => s.Contact.Name.Contains(someone));
The specified type member 'Name' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.
Any idea?
Thanks.