This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
hi, given EntityB : EntityA (STI) where EntityB has no members of its own except a value object Blah which has a ColumnX and ColumnY
i've got a sproc which returns an IList<EntityA>. Inside the sproc I'm currently selecting columns: EntityA.Id, EntityA.Column1, EntityA.Column2, EntityB.BlahColumnX as [Blah.ColumnX], EntityB.BlahColumnY as [Blah.ColumnY]
Iterating through IList<EntityA>, when yielding an EntityA, all properties are correctly mapped. But when yielding an EntityB, all properties off the base class are correctly mapped but EntityB.Blah is null. I have verified that the Blah columns do return data from the sproc. I can query an IEnumerable<EntityA> directly via the UOW and everything correctly serialises into entities (including EntityB.Blah) - so it's something specific about mapping from sproc results.
How do I get the valueobject properties mapped in for a child entity with STI, when returned from a query sproc? There must be some convention but I can't work out what it is. (have tried some variations of naming those valueobject columns). thanks |
|
|
I'm a bit confused by your description of what you're doing, but I think the answer may be "BlahColumnX". Your sproc is renaming the BlahColumnX columns to Blah.ColumnX. LightSpeed expects the BlahColumnX naming convention, as implemented in your table; the inserted full stop is preventing your sproc result set from adhering to that convention. |
|
|
have tried both BlahColumnX and Blah.ColumnX - neither is correctly deserialising Blah into the entity.
yes, that is a bit confusing though :) - i've sent you an email with a bit more detail. holler if you need more detail. thanks
|
|
|
I'm still confused. "BlahColumnX" works fine for me, but I am unclear about your inheritance scenario. You talk about CTI in the title, but STI in the post, but there appears to be more than one table in play. Could you provide me with a *simple* repro -- just the minimal number of entities with a minimal set of properties? I don't need to see your sproc, I'll create a dummy one; but I do need to see a complete, simple model (code, not a screenshot) that shows the entities you're trying to materialise. Thanks! |
|
|
ok, sorry, yes it is CTI. have attached small repro with clean model and db and mspec tests to show you exactly what i mean. sql for db and test data is in the project. thanks |
|
|
Thanks Justin. This was a bug with (deep breath) derived classes containing value objects when querying through a base class *and* using handwritten SQL instead of LightSpeed-generated SQL. There will be a candidate fix in the next nightly build -- let us know if you still run into problems. |
|
|
what?! you mean you didn't already have a unit test for that _exact_ scenario? ;) thanks. i had based the handwritten sql (in the sproc) on the sql emitted from the uow query which is why i was confused it didn't work. |
|
|
We have now *grin*. I forgot to say: the naming convention should be as you saw in the generated SQL from the UOW query, e.g. (source_expression) AS [TableB.BlahColumnX]. So my previous comment was not quite right -- the column name is the concatenation as indicated, but the table qualifier *is* needed in the alias. |
|
|
Just to let you know, we had a hiccup in the nightly build so this isn't up yet. Should be up in the next hour or two. |
|
|
ok, i've tried this out. so far i believe i have it working - but with a couple of very un-obvious workarounds:
i have to select the Id and discriminator columns with both vanilla and concatenated name styles. if i return only [Job].[Id] then no value populated into the Job.Id property if I return only [Job.Id] then nothing mapped into an entity at all if i return only [Job].[Type] then it can't work out what type to materialise and nothing mapped into an entity at all if i return only [Job.Type] then it doesn't populate the _type property.
select [Job].[Id], [Job].[Id] as [Job.Id], [Job].[Type], [Job].[Type] as [Job.Type], [Job].[Payload] as [Job.Payload], [Job].[Status] as [Job.Status], [Job].[Priority] as [Job.Priority], etc
so in short, it's working but ugly.
|
|
|
hey, sorry, have been off on other tasks, just got back to this one and i can't seem to get it to work. :( using the same repro solution that i sent you...
the sproc:
ALTER proc [dbo].[GetEntitiesViaSproc] as select a.* ,b.ValueObjectAPropertyX as [ValueObjectA.PropertyX] ,b.ValueObjectAPropertyY as [ValueObjectA.PropertyY] from entityA a left join entityb b on a.id = b.id
the LS assembly - I think this is the one from the nightly build after 7th Oct which should have the fix applied: Mindscape.LightSpeed, Version=4.0.887.18671, Culture=neutral, PublicKeyToken=360c8f37b466ebb2
and the test results are attached.
could you please verify sproc column names and LS assembly version. Should the fix be in that build? thanks justin |
|
|
The fix is in that build. But your column names are wrong. Should be "as TableB.ValueObjectAPropertyX" as described upthread. |
|
|
thanks for checking. yes, i had the column names wrong in the test solution. got the tests passing fine in there thanks. :)
just fyi, there is still some issue - but I can't work out what it is with my model and I don't have the latest LS source pulled down, or more particularly the inclination ;). have spent more than enough time on this one.
anyhow, the sproc as in the repro works for the tests but in order to get it to work with my model I've effectively had to make it like this:
ALTER proc [dbo].[GetEntitiesViaSproc] as select [a].[Id] , [a].[PropertyU] , [a].[PropertyV] , [a].[PropertyW] , [a].[Type], [a].[Id] AS [EntityA.ID], [a].[PropertyU] AS [EntityA.PropertyU] , [a].[PropertyV] AS [EntityA.PropertyV] , [a].[PropertyW] AS [EntityA.PropertyW] , [a].[Type] AS [EntityA.Type] ,b.ValueObjectAPropertyX as [EntityB.ValueObjectAPropertyX] ,b.ValueObjectAPropertyY as [EntityB.ValueObjectAPropertyY] ,c.ValueObjectBPropertyZ AS [EntityC.ValueObjectBPropertyZ] from [test].entityA a left join [test].entityb b on a.id = b.id LEFT JOIN [Test].entityc c ON a.id = c.id GO so the workaround is to pass the EntityA columns back in both forms - this allows LS to materialise the entities out of the sproc result properly .
thanks again for fixing. cheers justin |
|