0

I am trying to do something similar to using a lambda query inside a WCF operation parameter. I know there is no way to achieve this as lambda expressions are run-time and they can not be used in this way, but I think there are some solutions for this. My first idea is to use some search criteria class so that I can populate this class and then use it on server-side to build a lambda expression. My thoughts on a simple implementation for this class is something like :

public class PersonSearchCriteria
{
    public string FirstName {get; set;}
    public string LastName {get; set;}
    public int IdCardNumber {get; set;}

    Expression<Func<TSource, bool>> predicate
}

This is some pseudo code. I want to be able to create an instance of this class and based on this properties values' filter my database in my databasecontext (which in this case is EntityFramework 4.0 with selft tracking entities).

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Rati_Ge
  • 1,262
  • 2
  • 15
  • 37
  • I do not know how to build LINQ query out of this. if this class has same properties as my Person domain class how can I provide LINQ expression out of this so in my service when I receive this as a parameter I sample can write something like context.people.firstordefault(expression); – Rati_Ge Jan 31 '12 at 21:20

1 Answers1

0

I found some articles:

I found this by searching on wcf serialize expression

Community
  • 1
  • 1
John Saunders
  • 160,644
  • 26
  • 247
  • 397
  • I think u did not get my point. serializing and deserializing expression tree is very heavy process in terms of traffic and memory so the solution I am trying to achieve does not mean to serialize expression it will evaluate expression on server-side only – Rati_Ge Jan 31 '12 at 21:44
  • var search = new AlbumSearch(); search.PriceFrom = 5; search.PriceTo = 10; search.Artist = new ArtistSearch(){ Name = "Metallica" }; search.Genre = new GenreSearch(){ NameContains = "Metal" }; var albuns = from x in repository.All(search.GetExpression()) select x; this is very good example and a specially search.GetExpression() I want to have something like that I think – Rati_Ge Jan 31 '12 at 21:46