Home

Error : The expression of type '...' is not a sequence.

I use Linqpad extensively for querying databases. Today I got the following error when doing a Union operation between two result sets.
The expression of type 'System.Linq.IQueryable1[<>f__AnonymousType43[System.Int64,System.String]]' is not a sequence
Following is the sequence of steps I did.

I am using a Oracle database and added a connection in LinqPad using IQToolkit. I have 2 Tables with almost similar structure.

Table1
Field1 int
Field2 long
Field3 string

Table2
Field2 long
Field3 string
The table2 is similar in structure to Table1 except for the 'Field1' field. I want to join the data in two tables.

var firstTableData = (from data in Table1
select new{Field2 = data.Feild2, Field3 = data.Field3});

var secondTableData = (from data in Table2
select new{Field2 = data.Field2,Field3 = data.Field3});

var combined = firstTableData.Union(secondTableData);

combined.Dump();
At this point, Dump displays the combined Data from both tables.

Now when I use this combined data in a join with another query like

var newData = (from t3 in Table3
join c1 in combined on t3.Field2 equals c1.Field2
select {...});


In the above query, I am getting the issue

The expression of type 'System.Linq.IQueryable`1[<>f__AnonymousType4`3[System.Int64,System.String]]' is not a sequence

The structure of Table3 is as follows.

Table3
Field1 long
Field2 long

The Field2 in Table3 can contain values from Field2 of Table1 or Field2 of Table2. That is why i am combining the Field2 values from Table1 and Table2.

I have tried calling combined.AsQueryable(), combined.AsEnumerable() and also tried 'Concat' instead of 'Union' for combined.

var combined = firstTableData.Concat(secondTableData);
Nothing seemed to work.

Am I missing anything. It keeps me wondering that Dump() method does not have any such complaints. Please let me know if you need more information on this.

Can anybody suggest corrections to the linq queries(if they are not correct).

Thanks,
Satish

Can anybody suggest corrections to the linq queries i am using if they are not correct.

Comments

Sign In or Register to comment.