"Constant cannot be sequences" exception

"Constant cannot be sequences" exception

Postby PangoChris » Mon 21 Sep 2009 23:34

I have a query which fails for a reason I don't understand. I can make it work with a tiny change, but that change should be no business of the LINQ query and is at odds with my application's structure.

The query breaks when one of the tables is referenced from a variable instead of referenced directly from the datacontext, but it shouldn't matter because as this example demonstrates in both cases it's the exact same object:

Code: Select all
' this query will work
Dim results = From p In dc.Payments _
              Where Not (From t In dc.OnlineTransactions Where t.TxRefNum = p.TxRefNum).Any()
Console.WriteLine("result count: " & results.Count())

' this query will throw:
' "System.NotSupportedException: Constant cannot be sequences."
Dim allTransactions = dc.OnlineTransactions
Dim results2 = From p In dc.Payments _
               Where Not (From t In allTransactions Where t.TxRefNum = p.TxRefNum).Any()
Console.WriteLine("result count: " & results2.Count())


This means that this query can't be written without direct access to the data context, which is a problem since my application is tiered and the code that executes this query doesn't have access to the datacontext, just the relevant table objects.

(The query above is similar to a portion in my much larger query, I whittled the problem down to this repeatable example.)

Here's the stack trace:

Unhandled Exception: System.NotSupportedException: Constant cannot be sequences.
at Devart.Data.Linq.Provider.Query.bk.a(SqlNode A_0)
at Devart.Data.Linq.Provider.Query.bk.a(Expression A_0, LambdaExpression A_1)
at Devart.Data.Linq.Provider.Query.bk.b(MethodCallExpression A_0)
at Devart.Data.Linq.Provider.Query.bk.j(Expression A_0)
at Devart.Data.Linq.Provider.Query.bk.a(Expression A_0, LambdaExpression A_1, Boolean A_2)
at Devart.Data.Linq.Provider.Query.bk.b(MethodCallExpression A_0)
at Devart.Data.Linq.Provider.Query.bk.j(Expression A_0)
at Devart.Data.Linq.Provider.Query.bk.d(Expression A_0)
at Devart.Data.Linq.Provider.Query.bk.a(UnaryExpression A_0)
at Devart.Data.Linq.Provider.Query.bk.j(Expression A_0)
at Devart.Data.Linq.Provider.Query.bk.d(Expression A_0)
at Devart.Data.Linq.Provider.Query.bk.a(Expression A_0, LambdaExpression A_1)
at Devart.Data.Linq.Provider.Query.bk.b(MethodCallExpression A_0)
at Devart.Data.Linq.Provider.Query.bk.j(Expression A_0)
at Devart.Data.Linq.Provider.Query.bk.a(Expression A_0, LambdaExpression A_1, SqlNodeType A_2, Type A_3)
at Devart.Data.Linq.Provider.Query.bk.b(MethodCallExpression A_0)
at Devart.Data.Linq.Provider.Query.bk.j(Expression A_0)
at Devart.Data.Linq.Provider.Query.bk.i(Expression A_0)
at Devart.Data.Linq.Provider.DataProvider.a(Expression A_0)
at Devart.Data.Linq.Provider.DataProvider.h(Expression A_0)
at Devart.Data.Linq.DataQuery`1.System.Linq.IQueryProvider.Execute[S](Expression expression)
at System.Linq.Queryable.Count[TSource](IQueryable`1 source)

I'm using version 1.0.20.0 of Devart.Data.Linq and querying an Oracle database.


Thank you.
PangoChris
 
Posts: 12
Joined: Mon 14 Sep 2009 20:11

Postby AndreyR » Tue 22 Sep 2009 11:12

Thank you for the report, we have reproduced the problem.
I will let you know about the results of our investigation.
AndreyR
Devart Team
 
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Postby AndreyR » Tue 06 Oct 2009 12:56

We have fixed the problem. The fix will be included in the upcoming build.
AndreyR
Devart Team
 
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Postby PangoChris » Thu 15 Oct 2009 22:54

Thank you!
PangoChris
 
Posts: 12
Joined: Mon 14 Sep 2009 20:11

Postby F.Haemmerli » Tue 05 Jan 2010 06:07

Hello

I have still the same Exception using Devart querying MySQL database.

On this query:


[edited]
After a couple tests i found out that the problem is on the .sum()

This query still not works....
[/edited]
Code: Select all
foreach (KeyValuePair> pathExceptions in paths)
{
List tests = new List();

foreach (string pathException in pathExceptions.Value)
              tests.Add(new Test() { Value = pathException });

var fla =  (from ds in global.DirectoryScans
                       join dse in global.DirectoryScanEntries on ds.DirectoryScanId equals dse.DirectoryScanId
                       join sq1 in tests on dse.DirectoryPath.ToLower() equals sq1.Value.ToLower() into lj1
                       from p in lj1
                       select dse.DirectorySize).Sum();
}

[edited]
but without the .Sum()
[/edited]
Code: Select all
foreach (KeyValuePair> pathExceptions in paths)
{
List tests = new List();

foreach (string pathException in pathExceptions.Value)
         tests.Add(new Test() { Value = pathException });         
   var fla =  (from ds in global.DirectoryScans
                       join dse in global.DirectoryScanEntries on ds.DirectoryScanId equals dse.DirectoryScanId
                       join sq1 in tests on dse.DirectoryPath.ToLower() equals sq1.Value.ToLower() into lj1
                       from p in lj1
                       select dse.DirectorySize);
}

[edited]
it works.
[/edited]


Here's the stack trace:

at Devart.Data.Linq.Provider.Query.bk.a(SqlNode A_0)
at Devart.Data.Linq.Provider.Query.bk.a(Expression A_0)
at Devart.Data.Linq.Provider.Query.bk.b(Expression A_0, Expression A_1, LambdaExpression A_2, LambdaExpression A_3, LambdaExpression A_4)
at Devart.Data.Linq.Provider.Query.bk.b(MethodCallExpression A_0)
at Devart.Data.Linq.Provider.Query.bk.j(Expression A_0)
at Devart.Data.Linq.Provider.Query.bk.a(Expression A_0)
at Devart.Data.Linq.Provider.Query.bk.a(Expression A_0, Expression A_1, Expression A_2)
at Devart.Data.Linq.Provider.Query.bk.b(MethodCallExpression A_0)
at Devart.Data.Linq.Provider.Query.bk.j(Expression A_0)
at Devart.Data.Linq.Provider.Query.bk.a(Expression A_0, LambdaExpression A_1, SqlNodeType A_2, Type A_3)
at Devart.Data.Linq.Provider.Query.bk.b(MethodCallExpression A_0)
at Devart.Data.Linq.Provider.Query.bk.j(Expression A_0)
at Devart.Data.Linq.Provider.Query.bk.i(Expression A_0)
at Devart.Data.Linq.Provider.DataProvider.a(Expression A_0)
at Devart.Data.Linq.Provider.DataProvider.h(Expression A_0)
at Devart.Data.Linq.DataQuery`1.System.Linq.IQueryProvider.Execute[S](Expression expression)
at System.Linq.Queryable.Sum(IQueryable`1 source)


On the 06 October 2009 you postet the problem will be fixed with the upcoming build.

Im using the version 2.20.38 Standard Edition

On this site
http://www.devart.com/entitydeveloper/r ... story.html
I saw that the fix already should be done.

Is there any bug in this query?
I hope you can help me.


Thank you
F.Haemmerli
 
Posts: 1
Joined: Tue 05 Jan 2010 05:53

Postby AndreyR » Tue 05 Jan 2010 11:54

Thank you for the report, we will investigate the problem with the Sum method.
I will let you know about the results.
AndreyR
Devart Team
 
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Postby AndreyR » Wed 06 Jan 2010 10:37

The problem is that you are joining a LINQ to SQL collection (global) and a LINQ to Objects collection (tests).
This join cannot be resolved by pure LINQ to SQL code. By the way, is the second query executed successfully?
It should fail in run time with similar error.
AndreyR
Devart Team
 
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Constant cannot be sequence - :? Populate DDL w/ Years :?

Postby mabraham1 » Thu 03 Jun 2010 16:15

Hi,
Has this issue been fixed? I've got the same issue when trying to populate a drop-down list with a series of integer years. :?

Thank you for reviewing.

Here's the code:

Code: Select all
private static void getDDL_fiscYrs(ref DropDownList ddl)
{

            //Gets last year, this year, next year:
            int[] addlYrs = { System.DateTime.Today.Year - 1, System.DateTime.Today.Year, System.DateTime.Today.Year + 1 };

            //Gets all the years from past distributions
            var FYs = from c in DB.Distributions
                      select c.Initiatedondatetime.Value.Year;

            FYs = FYs.Union(addlYrs).Distinct();

            FYs = from yr in FYs
                  orderby yr descending
                  select yr;

            ddl.DataSource = FYs.ToList(); //array didn't work here

            try
            {
                ddl.DataBind();
                ddl.Items.Insert(0, " - Select Fiscal Year - "); //add spacer at top

                ddl.SelectedIndex = 0;
                if (!string.IsNullOrEmpty(UserSession.Fy))
                    ddl.SelectedValue = UserSession.Fy;
            }
            catch (Exception ex)
            {
                throw ex;
            }
}



Here's the StackTrace:

at Devart.Data.Linq.Provider.Query.x.a(SqlNode A_0)
at Devart.Data.Linq.Provider.Query.x.a(Expression A_0)
at Devart.Data.Linq.Provider.Query.x.a(Expression A_0, Expression A_1)
at Devart.Data.Linq.Provider.Query.x.b(MethodCallExpression A_0)
at Devart.Data.Linq.Provider.Query.x.j(Expression A_0)
at Devart.Data.Linq.Provider.Query.x.a(Expression A_0)
at Devart.Data.Linq.Provider.Query.x.e(Expression A_0)
at Devart.Data.Linq.Provider.Query.x.b(MethodCallExpression A_0)
at Devart.Data.Linq.Provider.Query.x.j(Expression A_0)
at Devart.Data.Linq.Provider.Query.x.b(Expression A_0, LambdaExpression A_1, bp A_2)
at Devart.Data.Linq.Provider.Query.x.b(MethodCallExpression A_0)
at Devart.Data.Linq.Provider.Query.x.j(Expression A_0)
at Devart.Data.Linq.Provider.Query.x.i(Expression A_0)
at Devart.Data.Linq.Provider.DataProvider.a(Expression A_0)
at Devart.Data.Linq.Provider.DataProvider.i(Expression A_0)
at Devart.Data.Linq.DataQuery`1.i()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at CommoDT.Connect.BaseDTC.getDDL_fiscYrs(DropDownList& ddl)
mabraham1
 
Posts: 6
Joined: Wed 21 Apr 2010 22:27

Postby AndreyR » Fri 04 Jun 2010 14:02

You are performing Union() of two collections. The first one is a .NET array, the second one is a LINQ to SQL IQueryable instance (not materialized yet). Then you call the ToList() method to materialize the union.
LINQ to SQL engine is unable to resolve such situation.
I recommend you to call ToList() before Union, like in the following example:
Code: Select all
private static void getDDL_fiscYrs(ref DropDownList ddl)
{

            //Gets last year, this year, next year:
            int[] addlYrs = { System.DateTime.Today.Year - 1, System.DateTime.Today.Year, System.DateTime.Today.Year + 1 };

            //Gets all the years from past distributions
            var FYs = (from c in DB.Distributions
                      select c.Initiatedondatetime.Value.Year).ToList();

            FYs = FYs.Union(addlYrs).Distinct();

            FYs = from yr in FYs
                  orderby yr descending
                  select yr;
            //...

Please let me know if anything goes wrong.
AndreyR
Devart Team
 
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Converting into int[] Arrays Worked

Postby mabraham1 » Fri 04 Jun 2010 15:05

AndreyR,
Converting both into int[] arrays worked fine. Thanks for the insight.

Mark :)

Code: Select all
                //Gets all the ordered, non-redundant years from past distributions
                int[] FYs = (from c in DB.Distributions
                          orderby c.Initiatedondatetime.Value.Year descending
                          select c.Initiatedondatetime.Value.Year).ToArray();

                  /*********************************************/
                 /** need to add other years if they don't exist in dist **/
                /*********************************************/
                int[] addlYrs = {
                                    System.DateTime.Today.Year - 1,     //Last year
                                    System.DateTime.Today.Year,          //This year
                                    System.DateTime.Today.Year + 1 }; //Nextyear
                FYs = FYs.Union(addlYrs).Distinct().ToArray();        //Combine, non-redundant
                ddl.DataSource =  //Sort Desc
                                (from yr in FYs orderby yr descending select yr);
                ddl.Items.Insert(0, " - Select Fiscal Year - ");          //Add Select Spacer
                ddl.DataBind();
                ddl.SelectedIndex = 0;

                //Preselect Enumerated Fiscal Year
                if (!string.IsNullOrEmpty(UserSession.Fy))
                    if (ddl.Items.Contains(new ListItem(UserSession.Fy)))
                        ddl.SelectedValue = UserSession.Fy;

[/code]
mabraham1
 
Posts: 6
Joined: Wed 21 Apr 2010 22:27


Return to LinqConnect (LINQ to SQL support)