Error: Instance argument cannot convert from System.Collections.Generic.IEnumerable to System.Linq.IQueryable. There is a type mismatch between the two sequences I am trying to union. Even after casting the sequences to IEnumerable or IQueryable, I am still unable to perform the union.
Also give that the anonymous types in two sequences match and the null values are handled
Loading
Hari MonePosted Oct 8, 2024, 9:34 PM
Thanks for your help.I was able to solve the issue.
Anupam MaitiPosted Oct 3, 2024, 1:08 PM
Please check below points:
Make sure the property names and types in both anonymous types match exactly.Even a slight difference in property names or types can cause this issue.
To avoid this issue is to use a named type (a class) instead of anonymous types. This ensures that both sequences have the same type.
If you want to continue using anonymous types, you can explicitly cast both sequences to a common type using the
Selectmethod.Jignesh KumarPosted Oct 1, 2024, 4:14 AM
Hello Hari Mone,
Have you verified the
SELECTstatement in both queries? They must have the same number of columns, with each column having the same data type.Example :
Muhammad Imran AnsariPosted Oct 1, 2024, 3:07 AM
Hi Hari,
As the error mentioned, "There is a type mismatch between the two sequences while union". You must verify the types of each data member or you can use the approach like project/map into a named type and then apply the union. Here is an emaple code which you can use accordingly.