none
Convert Expression<Func<D, bool>> to Expression<Func<E,bool>> RRS feed

  • Question

  • Hello guys,

    I have problem in Expression

    I have Entity

    public class User
    {
          public string Username{get;set;}
    }

    and I have DTO

    public class UserDTO
    {
          public string Username{get;set;}
    }

    then i have snippet code generic

    public E GetDetail(Expression<Func<D,bool>> predicateD)
    {
         // what should I do ??
         // should be predicate D to predicate E
         Expression<Func<E,bool>> predicateE = ??
         E entity = this.Repo.GetDetail(predicateE);
         return entity;
    }

    then i call to use

    Expression<Func<D, bool>> predicateD = x=>x.Username.Contains("sample");
    User user = this.UserFacade.GetDetail(predicateD);

    how to i can convert type DTO to Entity in Expression ??

    luliqzx


    • Edited by luliqzx Wednesday, June 6, 2012 5:04 PM miss D
    Wednesday, June 6, 2012 5:01 PM

Answers

  • You can't convert it, the two classes are different type, even though they contain the same properties, but both of them know nothing about each other. You need to write anothr seperate Expression for the other type.

    Go go Doraemon!

    Saturday, June 9, 2012 5:49 AM

All replies

  • You can't convert it, the two classes are different type, even though they contain the same properties, but both of them know nothing about each other. You need to write anothr seperate Expression for the other type.

    Go go Doraemon!

    Saturday, June 9, 2012 5:49 AM
  • You can't convert it, the two classes are different type, even though they contain the same properties, but both of them know nothing about each other. You need to write anothr seperate Expression for the other type.

    Go go Doraemon!

    thanks for response, Dorado999  .. :D

    Yes, there classes are different type, i'm stuck in there, may i'll try another solution to solve my problem. :D

    luliqzx

    Saturday, June 23, 2012 7:23 PM