QuerySpec, Hierarchy and dynamic query

Posts   
 
    
mihies avatar
mihies
User
Posts: 800
Joined: 29-Jan-2006
# Posted on: 20-Sep-2016 14:53:29   

Let's say I have this Target Per Entity Hierarchy:

(abstract)TableA Id TableB: TableA NumericValue (int) TableC: TableA BooleanValue (bool)

I am doing a projection to a flat list, i.e. to a class

ProjectionClass Id, NumericValue, BooleanValue

Query:

var query = qf.Create().Select( () => { new ProjectionClass { Id = TableAFields.Id.ToValue<int>(), NumericValue= TableBFields.NumericValue .ToValue<int?>(), BooleanValue = TableCFields.BooleanValue.ToValue<bool?>() } }) .From(qf.TableA);

This is fine, but I'd like to include the information of source entity (TableB or TableC). Is there a strong typed way to get this info?

I think a non stong typed is by using WithProjector and then Get<T> method.

);

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 20-Sep-2016 18:01:19   

So do you want to add another property to the ProjectionClass indicating the type of the subEntity?

mihies avatar
mihies
User
Posts: 800
Joined: 29-Jan-2006
# Posted on: 20-Sep-2016 18:04:05   

Walaa wrote:

So do you want to add another property to the ProjectionClass indicating the type of the subEntity?

Yes. Another use case would be using WithProjector.

Now, I know I could access discriminator field directly, but that wouldn't be strong typed. (I'd have to map discriminator value somehow).

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 20-Sep-2016 18:57:13   

What about mapping the discriminator value to an Enum?

mihies avatar
mihies
User
Posts: 800
Joined: 29-Jan-2006
# Posted on: 20-Sep-2016 21:38:27   

Walaa wrote:

What about mapping the discriminator value to an Enum?

That's what I'm doing now, I was just wondering whether there was an out of the box feature that would do that for me. Also doing it like I'm doing and you suggested might break if discriminator values change for some reason.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 21-Sep-2016 15:17:42   

No there's no other way to do this, because the type of the entity represented by the row isn't known at projection of the query, as it never materializes into entities: it's just a row of data.

Frans Bouma | Lead developer LLBLGen Pro
mihies avatar
mihies
User
Posts: 800
Joined: 29-Jan-2006
# Posted on: 21-Sep-2016 15:27:51   

Otis wrote:

No there's no other way to do this, because the type of the entity represented by the row isn't known at projection of the query, as it never materializes into entities: it's just a row of data.

OK, thanks. I was thinking that you know the discriminator values and what entity types they map to. So one could easily create mappings through a template. But that's not a problem as I can create such a template by myself.