c# - Perform a LINQ query without using NotMapped properties in EF -


i have following class:

public class contact {     public int contactid { get; set; }     public string firstname { get; set; }     public string lastname { get; set; } } 

and following data:

  • 1 / john / doe
  • 2 / mike / tyson
  • 3 / john / mc enroe
  • 4 / stef / doe

now need let user search contacts this:

  • john doe > contacts having firstname john , lastname doe
  • john > contacts having first name john
  • doe > contacts having last name doe
  • ...

i tried add notmapped element class , perform search on (full) name linq query not work notmapped elements.

[notmapped] public string name {     {         return firstname + " " + lastname;     } }  var = "john doe"; requests.where(s => s.contact.name.contains(someone)); 

the specified type member 'name' not supported in linq entities. initializers, entity members, , entity navigation properties supported.

any idea?

thanks.

i think don't need create not mapped property achieve need. can try this:

var = "john doe"; var contacts=context.contacts.where(c => string.concat(c.firstname, " ", p.lastname).contains(someone)); 

the string.concact method supported ef.


Comments