Automapper has a very nice extensions for getting projections.
In BL of our application we can just define methods like this:
IEnumerable<TEntityProjection> GetProjections()
{
return _context.EntitiesSet.Project().To<TEntityProjection>();
}
This helps BL to stay quite simple. We do not need many different methods for each projection variant.
But... WCF service does not support open generics.
So I'm looking for the solution which allows service clients to get only desired properties of the entity.
Possible solution is Linq over WCF (based on BLToolkit). Under the hood, the linq query parse to SqlQuery (SQL AST), serialize and send to WCF LINQService. The service creates a sql query for DB (SQl Server, Oracle, MySql, etc), executes it and returns data. Anonymous types are supported.
Query sample:
var client = new DataModel();
var q = from p in client.Person
select new
{
p.PersonID,
p.FirstName,
p.MiddleName,
p.LastName,
p.Gender
};
foreach (var p in q)
Console.WriteLine(p);
More info: http://bltoolkit.net/Doc.LinqDataContext.ashx
Sample: https://github.com/igor-tkachev/bltoolkit/blob/master/Demo/Linq/OverWCF/Program.cs