vendredi 11 mars 2016

Use reflection and lambda expression with linq

I need to filter a collection of items by verifing the value of a flag named deletion_date

 public List<T> GetAll()
 {
   if (context == null) context = new ajtdevEntities();
   return context.Set<T>().Where(p => p.GetType().GetProperty("deletion_date") == null).ToList();
 }

I get an exception when I used this generic method

LINQ to Entities does not recognize the method ' System.Reflection.PropertyInfo GetProperty ( System.String )' , and the latter can not be translated into term store.

How can I fix this method?





Aucun commentaire:

Enregistrer un commentaire