Incorrect SQL translation:

Wrong SELECT before CAST -> Cols 144 and 380!

Exception:


Xtensive.Orm.SyntaxErrorException was unhandled
  Message=SQL error occured.
SQL error details 'Type: SyntaxError;'
Query 'SELECT [a].[Id], [a].[TypeId], [a].[Name], [a].[Name2], [a].[Val] FROM (SELECT [b].[Id], 194 AS [TypeId], [b].[Name], [b].[Name2], [b].[Val], (SELECT CAST((CASE WHEN EXISTS (SELECT * FROM [TestMain-TestSubAs-TestSubA] [c] INNER JOIN [TestSubA] [d] ON ([c].[TestSubA] = [d].[Id]) WHERE (([c].[TestMain] = [b].[Id]) AND ([d].[Val] = 1))) THEN 1 ELSE 0 END)  AS bit)) AS [c01umn], (SELECT CAST((CASE WHEN EXISTS (SELECT * FROM [TestMain-TestSubBs-TestSubB] [e] INNER JOIN [TestSubB] [f] ON ([e].[TestSubB] = [f].[Id]) WHERE (([e].[TestMain] = [b].[Id]) AND ([f].[Val] = 2))) THEN 1 ELSE 0 END)  AS bit)) AS [c01umn1], (CASE WHEN (([b].[Name2] IS NULL) OR ((DATALENGTH(LTRIM(RTRIM([b].[Name2]))) / 2) = 0)) THEN [b].[Name] ELSE [b].[Name2] END) AS [c01umn2] FROM [TestMain] [b] WHERE (EXISTS (SELECT * FROM [TestMain-TestSubAs-TestSubA] [c] INNER JOIN [TestSubA] [d] ON ([c].[TestSubA] = [d].[Id]) WHERE (([c].[TestMain] = [b].[Id]) AND ([d].[Val] = 1))) AND EXISTS (SELECT * FROM [TestMain-TestSubBs-TestSubB] [e] INNER JOIN [TestSubB] [f] ON ([e].[TestSubB] = [f].[Id]) WHERE (([e].[TestMain] = [b].[Id]) AND ([f].[Val] = 2))))) [a] ORDER BY [a].[c01umn2] ASC;'
Original message 'There was an error parsing the query. [ Token line number = 1,Token line offset = 144,Token in error = SELECT ]'
  Source=Xtensive.Orm


Entities:


[Serializable]
[HierarchyRoot]
public class TestMain : Entity
{
  public TestMain( Session session ) : base( session ) { }

[Field, Key] public int Id { get; private set; }

[Field] public string Name { get; set; }

[Field] public string Name2 { get; set; }

[Field] public int Val { get; set; }

[Field] public EntitySet<TestSubA> TestSubAs { get; private set; }

[Field] public EntitySet<TestSubB> TestSubBs { get; private set; } }

[Serializable] [HierarchyRoot] public class TestSubA : Entity { public TestSubA( Session session ) : base( session ) { }

[Field, Key] public int Id { get; private set; }

[Field] public int Val { get; set; } }

[Serializable] [HierarchyRoot] public class TestSubB : Entity { public TestSubB( Session session ) : base( session ) { }

[Field, Key] public int Id { get; private set; }

[Field] public int Val { get; set; } }


Query:


Session.Query.All<TestMain>()
.Where( m => m.TestSubAs.Any( a => a.Val == 1 ) &&
        m.TestSubBs.Any( b => b.Val == 2 ) )
.OrderBy( m => m.Name2 == null || m.Name2.Trim().Length == 0 ?
          m.Name : m.Name2 ).ToList();

asked Sep 17 '12 at 05:50

TeaMan's gravatar image

TeaMan
140141418

edited Sep 17 '12 at 06:11


One Answer:

Hello TeaMan.

The problem is fixed and fix will be included in 4.5.5 and 4.6.0 releases.

Thanks for reporting.

answered Sep 17 '12 at 07:19

Denis%20Krjuchkov's gravatar image

Denis Krjuchkov
179325

Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

Subscription:

Once you sign in you will be able to subscribe for any updates here

Tags:

×120
×5

Asked: Sep 17 '12 at 05:50

Seen: 2,612 times

Last updated: Sep 17 '12 at 07:19

powered by OSQA