Use delegate for Projection in Linq to SQL
Posted
by Redeemed1
on Stack Overflow
See other posts from Stack Overflow
or by Redeemed1
Published on 2010-05-25T16:36:14Z
Indexed on
2010/05/25
16:41 UTC
Read the original article
Hit count: 289
LINQ
|linq-to-sql
I have code something like this in an IRepository implementation in Linq to Sql:
var newlist = from h in list where h.StringProp1 == "1"
select new MyBusinessBO{
firstProp = h.StringProp1,
secondProp = h.StringProp2
};
The projection into MyBusinessBO is not difificult but when the Business Object has many properties the projection code becomes very lengthy. Also, as the projection can occur in several places in the Repository we break the DRY principle.
Is there any way to abstract out the projection or replace it with a delegate?
I.e. replace the code
firstProp = h.StringProp1,
secondProp = h.StringProp2
with something reusable?
© Stack Overflow or respective owner