score:3
the generated sql includes the following line, where @p4 corresponds to the blahblahblah=false
line in your projection:
declare @p4 int = 0
and the int that is returned from the query can't be converted to a bool. i don't know whether or not this is a linq to sql bug (seems like it), but there is a workaround. basically you need to drop the blahblahblah=false
from the anonymous type projected, then .tolist()
or .toarray()
the result, and finally add the bool field in a linq to objects projection:
var one =
(from ch in test_charts
join a in test_chart_series on ch.chartid equals a.chartid into a_join
from cs in a_join.defaultifempty()
join ycols in test_query_cols on new { key1 = cs.yaxis, key2 = ch.queryid } equals new { key1 = ycols.colname, key2 = ycols.queryid }
where ch.chartid == 1
select new
{
ch.chartid,
position = 0,
ycols.queryid,
ycols.otherblah,
blahblahblah = cs.blahblahblah
}).tolist();
var two =
(from ch in test_charts
join xcol in test_query_cols on new { key1 = ch.xaxis, key2 = ch.queryid } equals new { key1 = xcol.colname, key2 = xcol.queryid }
where ch.chartid == 1
select new
{
ch.chartid,
position = 0,
xcol.queryid,
xcol.otherblah
}).tolist();
var three =
from x in two
select new
{
x.chartid,
x.position,
x.queryid,
x.otherblah,
blahblahblah = false
};
var four = one.union(three).distinct();
note that this results in two sql queries, not one.
edit
also, distinct() can be left out, since union doesn't include duplicates. i should have actually read the code that i copied and pasted!
Source: stackoverflow.com
Related Query
- LINQ union with BIT column causing Specified cast is not valid error
- LINQ Specified Cast is Not Valid with a ushort Table Column
- Error in LINQ to SQL: specified cast is not valid
- Linq To Data set error System.InvalidCastException: Specified cast is not valid
- LINQ - Specified cast is not valid with dataview use
- Specified cast is not valid Linq Query
- Linq To SQL - Specified cast is not valid - SingleOrDefault()
- Specified cast is not valid in linq query
- Insert throw error : Specified cast is not valid
- Linq result Int error: Specified cast is not valid
- Updating a NVarChar(MAX) column with Linq causing an error
- LINQ to List: Specified cast is not valid
- Linq to SQL: specified cast is not valid
- Linq Specified cast is not valid
- Specified cast is not valid using one to many relationship with EntitySet
- asp.net - Specified cast not valid Linq
- LINQ Union causing error if a column in the query is DateTime
- Specified cast is not valid when filtering a DataTable where the column can be int32 or int64
- Linq Query Message: Specified cast is not valid
- Specified cast is not valid while fetching column details from SQL Server
- Linq to sql poco approach specified cast is not valid
- Linq to dataset - Sum method - Specified cast is not valid
- specified cast is not valid in linq to sql
- The specified cast from a materialized 'System.Int32' type to the 'System.Double' type is not valid
- Why does the Linq Cast<> helper not work with the implicit cast operator?
- System.InvalidCastException: Specified cast is not valid. Error
- Error with Union in Linq to Entities
- why .ToList().Distinct() throws error but not the .Distinct().ToList() with linq query
- The specified cast from a materialized 'System.Int32' type to the 'System.Int64' type is not valid
- Linq to Sql, System.Exception cast is not valid
More Query from same tag
- how to delete a record from a database using linq?
- How to map two different lists to one list?
- Linq distinct record containing keywords
- Comparing Nullable Datetime got error Only parameterless constructors and initializers are supported in LINQ to Entities
- C# LINQ query on multidimensional array
- nHibernate unable to cast Boolean to String
- LINQ Projection AFTER optional parameter filtering
- Multiple nested GroupBy to turn tabular data into a class
- Linq aggregate from Dictionary
- Linq query returns half the results
- How is an Enumerable converted to a Dictionary?
- Performant way to fetch all rows inside and outside parent record
- Grid is not showing some values for columns from two tables
- list contains an ID in linq
- Conditional LINQ where statement?
- How to query first and last name in Entity Framework?
- Get top n records with top m of relative table in Entity Framework
- Extract results from List<Customers> using LINQ
- Linq - How to get types participating in expression
- How to call a method in Linq query?
- LINQ to SQL, check if connection to connection string is valid
- Linq to SQL Join, Order by, Group by
- Using linq to remove a href tag inside cdata in xml file
- lock keyword on a LINQ Parallel.ForEach<> loop
- linq equivalent sql query "not in (select query)"
- Expression.Body as MemberExpression returns null for primitive property
- Entity framework LINQ query for DB2
- Is there a faster way to check for an XML Element in LINQ to XML?
- linq - convert nested foreach loop
- Linq where clause using filter object