Forum:  LLBLGen Pro Runtime Framework

Thread:  Queryspec Projection Capability

arschr (User)   Posted on: 20-Jun-2014 18:22:06.
I'm trying this with LlblGen v4.2 beta but don't think it is specific to that version.

I have an entity File and a related entity FileActivity (1->n).
I am trying to use queryspec to retrieve a set of File entities and the related FileActivity entities.

I would like to project the File entities into a List<FileModel> where FileModel is a poco and FileModel has a property which is a List<FileActivityModel> which would hold the related projected FileActivity entities.

I think I see something close to this in the documentation here

var qf = new QueryFactory();
var q = qf.Customer
     .Where(CustomerFields.Country == "Germany")
     .Select(() => new
        CustomerId = CustomerFields.CustomerId.ToValue<string>(),
        Orders = qf.Order
             .Select(() => new
                OrderId = OrderFields.OrderId.ToValue<int>(),
                OrderDate = OrderFields.OrderDate.ToValue<DateTime?>()

But I don't see how to make the Orders collection in the help a List<OrderModels>

Can it be done? If so a sample would help.

Then a related question would be how to do the same projection when the relateed entities are retrieved using .WithPath and .WithSubPath?
daelmo (Support Team)   Posted on: 21-Jun-2014 03:53:10.
You can use a basic projection right in the .Select construct:
return qf.Create("oq")
            .Select(() => new OrderData
                CustomerId = OrderFields.CustomerId.ToValue<string>(),
                OrderId = OrderFields.OrderId.ToValue<int>(),
                EmployeeIdAsFloat = OrderFields.EmployeeId.ToValue<int>()

You also could use .WithProjector, which is more powerful, as you can write your conversion code. See Specifying the type of a DynamicQuery resultset for explanation and examples.