let there be :
Expression<Func<Message, bool>> exp1 = x => x.mesID == 1;
Expression<Func<MessageDTO, bool>> exp2 = x => x.mesID == 1;
now i need to pass exp1 to _db.Messages.where(exp1);
problem is i only have exp2, i need to convert the type to Message , All properties are the same !
now i do this :
var par = Expression.Parameter(typeof(Message));
var ex = (Expression<Func<Message, bool>>)Expression.Lambda(exp2.Body, par);
problem with this is the input paramter gets changed yes ! but the x inside the body of the lambda "x.mesID" is of the old type.
any way to change all the parameters type in the body too or change the input parameter in away it reflect the body too ?
i guess this is a big problem i always have with LINQ , since between layers i cant pass the generated classes , as this will make layers coupled , so i have to make light weight classes , now how do i use a method like _db.Messages.where(); from busiess layer ?!! while busniess layer doesnt know anything about Message type it only know MessageDTO.
am i missing something ?
thanks in advance.