Hello,
I have a L INQ to Sql statement that is run against several joined tables, with one "MajorTable", which has links to all other. Problem is that if in select statement I have nested conditions, they are translated to nested case statements. Since CASE statements are nested I hit a limit of maximum of 10 nested CASE statements. Solution would be to translate it to one CASE statement with several WHEN statements.
Explanation:
Statement looks like:
C#var myDataJoined = MajorTable
.Join(new XPQuery<Table1>(session),
link => link.ToId,
Table1Rec => Table1Rec.Oid,
(link, Table1Rec) => new { Table1Rec = Table1Rec, link = link })
.Join(new XPQuery<Table2>(session),
link => link.link.ToId,
Table2Rec => Table2Rec.Oid,
(link, Table2Rec) => new { Table2Rec = Table2Rec, Table1Rec = link.Table1Rec, link = link.link })
.Join(new XPQuery<Table3>(session),
link => link.link.ToId,
Table3Rec => Table3Rec.Oid,
(link, Table3Rec) => new { Table3Rec = Table3Rec, Table2Rec = link.Table2Rec, Table1Rec = link.Table1Rec, link = link.link })
.Join(new XPQuery<Table4>(session),
link => link.link.ToId,
Table4Rec => Table4Rec.Oid,
(link, Table4Rec) => new { Table4Rec = Table4Rec, Table3Rec = link.Table3Rec, Table2Rec = link.Table2Rec, Table1Rec = link.Table1Rec, link = link.link });
var resultingData = linksJoined.Select(entity => new MyRow()
{
Oid = entity.Table1Rec != null ? entity.Table1Rec.Oid : (entity.Table2Rec != null ? entity.Table2Rec.Oid : (entity.Table3Rec != null ? entity.Table3Rec.Oid : (entity.Table4Rec != null ? entity.Table4Rec.Oid : (Guid.Empty)))),
SomeData = entity.Table1Rec != null ? entity.Table1Rec.Col1 : (entity.Table2Rec != null ? entity.Table2Rec.LastName : (entity.Table3Rec != null ? entity.Table3Rec.SomeCol : (entity.Table4Rec != null ? "FixedText" : ("NO DATA")))),
});
This query is translated to SQL which looks like:
C#select
case when not (N1.OID is null) then N1.OID
else case when not (N2.OID is null) then N2.OID
else case when not (N3.OID is null) then N3.OID
else case when not (N4.OID is null) then N4.OID
else '00000000-0000-0000-0000-000000000000' end end end end,
case when not (N1.OID is null) then N1.Col1
else case when not (N2.OID is null) then N2.LastName
else case when not (N3.OID is null) then N3.SomeCol
else case when not (N4.OID is null) then N'Fixed text'
else N'NO DATA' end end end end
...
Instead it should be translated to:
C#select
case when not (N1.OID is null) then N1.OID
when not (N2.OID is null) then N2.OID
when not (N3.OID is null) then N3.OID
when not (N4.OID is null) then N4.OID
else '00000000-0000-0000-0000-000000000000' end,
case when not (N1.OID is null) then N1.Col1
when not (N2.OID is null) then N2.LastName
when not (N3.OID is null) then N3.SomeCol
when not (N4.OID is null) then N'Fixed text'
else N'NO DATA' end
...
As it is clear, this statement can run even if there are more when statements.
Thank you.
Hello Muris,
Thanks for contacting us on this. We are working on your issue and will get back to you as soon as we can. I would greatly appreciate it if you could post your deguggable test project along with the database backup so we can replicate and research this behavior faster locally. Thanks in advance.
I could provide you a demo but on 17th or 18th.
It is not so complex. One table that has Oids (stored as a Guid) of records from other (lets say 15) tables.
Then make a query to get data from relevant table depending where oid is stored.
if it is from table 1, then grab some column
if it is from table 2, then grab some column from this table
and so on.
If it is unclear, I can build a demo, but next week soonest :)
Thanks for your quick reply - yes, that would be great (so we can ensure the same scenario and conditions) and we will wait for your demo, thanks!
In the meantime, I have passed your ticket to our XPO developers for review.
Hi Muris,
I think we do not need your sample as we have finished our research and your idea makes sense. Our team appreciates your input in this regard and will take it into account for the future, though we cannot promise any implementation date at this time.
Hi Dennis,
Does this mean not in next 6 months or a year or?
Hi Muris, I cannot provide this info at this time as this feature is not planned for any specific release yet.
Any chance you give me some hints, I will change translator in my local version?
Muris,
Our initial research shows that this task cannot be accomplished in the current version without modifications of the XPO source code and then its further recompilation. At this stage, we do not have complete instructions for accomplishing this customization yet as this requires further research. While allocating our R&D resources at this research right away is not really possible (because that would technically mean implementing this feature bypassing or affecting other release plans), we will try to expedite this particular improvement regarding future updates, though as I said above I cannot give 100% implementation promises at this time. You will automatically be informed of any ticket status changes via email, as always.
Muris,
We have made an exception for you and implemented this feature in the next minor update. We hope to hear from you on how this works once the new version is out. Thanks.
Thank you all guys, especially you Dennis for putting this in next release! You are the best!