Coffeehouse Thread

9 posts

Lambda inside wcf operationcontract parameters

Back to Forum: Coffeehouse
  • User profile image
    ratige

    Hi everyone what I am trying to do is something similar to using lambda query inside WCF operation parameter. as I know there is no way to achieve this es lambda expressions are run-time and they can not be used in this way, but I think of 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 some lambda expression. my thoughts on 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 so I want to be able to create 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.

  • User profile image
    cbae

    OK. Did you have a particular question?

  • User profile image
    Maddus Mattus
  • User profile image
    vesuvius

    @ratige: You need to change your way of thinking, as what you want to to, is the worst way to approach web service design.

    The prime aim of any service is to be as stateless as possible, your search function needs to be closer (BLL) or in your data access layer, and not exposed in your data contracts. Desist from trying to make this work in this way, it will only end in tears (guaranteed).

  • User profile image
    blowdart

    , vesuvius wrote

    @ratige: You need to change your way of thinking, as what you want to to, is the worst way to approach web service design.

    The prime aim of any service is to be as stateless as possible, your search function needs to be closer (BLL) or in your data access layer, and not exposed in your data contracts. Desist from trying to make this work in this way, it will only end in tears (guaranteed).

    +1. You're passing messages, not classes, objects or functions. Now imaging passing an update or delete function Wink

  • User profile image
    ratige

    u did not get my point I think. this class has nothing to do with my data-context it is sample search criteria and as I am using .Net to.net scenario I always know that clients will always use NET to connect to service. I do not see any example of delete operation as this will be only single operation used for search on server-side I want something like

    var Person = context.Persons.FirstOrDefault(search.GetExpression());
    

    and there is nothing wrong with this as SearchCriteria is Message if I do this in a way u call service oriented I will have to create operationcontracts for each of parameters I could get as a filter criteria on client-side and I will end with tones of methods

    GetPersonByName
    GetPersonByBirthDate
    GetPersonByIdCardNumber

    and there are more than 60 entities and 1/3 of them will be search enabled. so pleas before u post your replay first carefully read question and after that give your remarks. I am not asking weather this is good or bad way all I am asking about is how to implement and if one says never do this first let me know how would u do this and after that I will think of better way.

    @blowdart:

    Messages not classes DataContract and DataMember this is how message is defined and we both know this as I wrote this is pseudo code so I just want to illustrate idea. if u mean custom messages with message headers  this is another story and not related to my question

  • User profile image
    JoshRoss

    After reading the question several times, I am firmly in the "you're doing it wrong" camp. If you have sparse data, use Json, It is fully supported by WCF.

  • User profile image
    davewill

    Why not call "GetPerson" passing it a PersonSearchCriteria object that is populated with the criteria to search on?  The backend would search based on the not null fields.

  • User profile image
    Maddus Mattus

    Use WCF DataServices, it's created specifically for these types of scenarios!

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.