Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > LLBLGen Pro > LLBLGen Pro Runtime Framework> Reuse QuerySpec projection
 

Pages: 1
LLBLGen Pro Runtime Framework
Reuse QuerySpec projection
Page:1/1 

  Print all messages in this thread  
Poster Message
scotru
User



Location:
College Place, WA
Joined on:
16-Feb-2006 01:03:42
Posted:
100 posts
# Posted on: 10-Oct-2016 01:15:02.  
I have a projection mapping lambda that I use with a dynamic QuerySpec query in LLBLGen

Code:
            var qf = new QueryFactory();
            var q = qf.Create()
                 .From(qf.Leave.LeftJoin(qf.Student).On(LeaveFields.StudentId == StudentFields.StudentId))
                 .Where(pred)
                 .OrderBy(LeaveFields.RequestDate.Descending())
                 .Select( () => new LeaveDTO
                 {
                     LeaveId = LeaveFields.LeaveId.ToValue<int>(),
                     RequestDate = LeaveFields.RequestDate.ToValue<DateTime>(),
                     LeaveDepart = LeaveFields.LeaveDepart.ToValue<DateTime>(),
                     LeaveReturn = LeaveFields.LeaveReturn.ToValue<DateTime>(),
                     ApprovalType = LeaveFields.ApprovalType.ToValue<string>(),
                     StudentId = StudentFields.StudentId.ToValue<int>(),
                     SchoolId = StudentFields.Schoolid.ToValue<string>(),
                     FirstName = StudentFields.FirstName.ToValue<string>(),
                     LastName = StudentFields.LastName.ToValue<string>(),
                 });



I would like to reuse the projection lambda in other queries called in other functions:

Code:
    () => new LeaveDTO
    {
        LeaveId = LeaveFields.LeaveId.ToValue<int>(),
        RequestDate = LeaveFields.RequestDate.ToValue<DateTime>(),
        LeaveDepart = LeaveFields.LeaveDepart.ToValue<DateTime>(),
        LeaveReturn = LeaveFields.LeaveReturn.ToValue<DateTime>(),
        ApprovalType = LeaveFields.ApprovalType.ToValue<string>(),
        StudentId = StudentFields.StudentId.ToValue<int>(),
        SchoolId = StudentFields.Schoolid.ToValue<string>(),
        FirstName = StudentFields.FirstName.ToValue<string>(),
        LastName = StudentFields.LastName.ToValue<string>(),
    }


How?
  Top
daelmo
Support Team



Location:
Guatemala City
Joined on:
28-Nov-2005 23:35:24
Posted:
8036 posts
# Posted on: 10-Oct-2016 10:22:22.  
You could declare an expression and reuse it when needed:
Code:
System.Linq.Expressions.Expression<Func<LeaveDTO>> mySelector = ( () => new LeaveDTO
    {
        LeaveId = LeaveFields.LeaveId.ToValue<int>(),
        RequestDate = LeaveFields.RequestDate.ToValue<DateTime>(),
        LeaveDepart = LeaveFields.LeaveDepart.ToValue<DateTime>(),
        LeaveReturn = LeaveFields.LeaveReturn.ToValue<DateTime>(),
        ApprovalType = LeaveFields.ApprovalType.ToValue<string>(),
        StudentId = StudentFields.StudentId.ToValue<int>(),
        SchoolId = StudentFields.Schoolid.ToValue<string>(),
        FirstName = StudentFields.FirstName.ToValue<string>(),
        LastName = StudentFields.LastName.ToValue<string>(),
    };

// ....

var q = qf.Create()
    .From(qf.Leave.LeftJoin(qf.Student).On(LeaveFields.StudentId == StudentFields.StudentId))
    .Where(pred)
    .OrderBy(LeaveFields.RequestDate.Descending())
    .Select(mySelector);



David Elizondo
LLBLGen'ing (articles and code snippets) | linkedin | twitter
 
Top
scotru
User



Location:
College Place, WA
Joined on:
16-Feb-2006 01:03:42
Posted:
100 posts
# Posted on: 16-Oct-2016 21:44:27.  
Thanks! Exactly what I was looking for.
  Top
Pages: 1  


Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.12172008 Final.