C
Chuck P
I tried to make some complex linq queries easier to read by pulling some of
the queries out.
This works fine:
var qAllJobDescriptions = from j in dc.Jobs
select j;
var qAllOracleJobCodes = from o in dc.OracleJobCodes
select o.JOBCODE;
GridView_Ex3.DataSource = from j in qAllJobDescriptions
where
!(qAllOracleJobCodes).Contains(j.OracleJobCode)
select j;
This works fine:
var qActiveJobDescriptions = from j in dc.Jobs
where DateTime.Today >= j.StartDate
&& (j.EndDate == null || (DateTime.Today <
j.EndDate.Value.AddDays(1)))
select j;
var qActiveOracleJobCodes ="";
GridView_Ex2.DataSource = (from j in qActiveJobDescriptions
where !(from o in dc.OracleJobCodes
where
DateTime.Today >= o.DATEFROM
&& (o.DATETO == null ||
(DateTime.Today < o.DATETO.Value.AddDays(1)))
select
o.JOBCODE).Contains(j.OracleJobCode)
select new { j.OracleJobCode })
This blows up when I move the where !(....).Contains into its own query.
Seems odd because I did a similar thing in the first example.
:
var qActiveJobDescriptions = from j in dc.Jobs
where DateTime.Today >= j.StartDate
&& (j.EndDate == null || (DateTime.Today <
j.EndDate.Value.AddDays(1)))
select j;
var qActiveOracleJobCodes =from o in dc.OracleJobCodes
where
DateTime.Today >= o.DATEFROM
&& (o.DATETO == null ||
(DateTime.Today < o.DATETO.Value.AddDays(1)))
select o.JOBCODE;
GridView_Ex2.DataSource = (from j in qActiveJobDescriptions
where
!(qActiveOracleJobCodes).Contains(j.OracleJobCode)
select new { j.OracleJobCode })
((System.Exception)((new
System.Linq.SystemCore_EnumerableDebugView<<string>>(((System.Data.Linq.DataQuery<<string>>)(GridView_Ex2.DataSource)))).Items)).StackTrace
at System.Data.Linq.SqlClient.SqlFactory.Member(SqlExpression expr,
MemberInfo member)
at
System.Data.Linq.SqlClient.QueryConverter.VisitMemberAccess(MemberExpression
ma)
at System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node)
at System.Data.Linq.SqlClient.QueryConverter.VisitExpression(Expression
exp)
at System.Data.Linq.SqlClient.QueryConverter.VisitCast(UnaryExpression c)
at System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node)
at System.Data.Linq.SqlClient.QueryConverter.VisitExpression(Expression
exp)
at System.Data.Linq.SqlClient.QueryConverter.VisitBinary(BinaryExpression
b)
at System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node)
at System.Data.Linq.SqlClient.QueryConverter.VisitExpression(Expression
exp)
at System.Data.Linq.SqlClient.QueryConverter.VisitBinary(BinaryExpression
b)
at System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node)
at System.Data.Linq.SqlClient.QueryConverter.VisitExpression(Expression
exp)
at System.Data.Linq.SqlClient.QueryConverter.VisitWhere(Expression
sequence, LambdaExpression predicate)
at
System.Data.Linq.SqlClient.QueryConverter.VisitSequenceOperatorCall(MethodCallExpression mc)
at
System.Data.Linq.SqlClient.QueryConverter.VisitMethodCall(MethodCallExpression mc)
at System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node)
at System.Data.Linq.SqlClient.QueryConverter.VisitSelect(Expression
sequence, LambdaExpression selector)
at
System.Data.Linq.SqlClient.QueryConverter.VisitSequenceOperatorCall(MethodCallExpression mc)
at
System.Data.Linq.SqlClient.QueryConverter.VisitMethodCall(MethodCallExpression mc)
at System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node)
at System.Data.Linq.SqlClient.QueryConverter.VisitContains(Expression
sequence, Expression value)
at
System.Data.Linq.SqlClient.QueryConverter.VisitSequenceOperatorCall(MethodCallExpression mc)
at
System.Data.Linq.SqlClient.QueryConverter.VisitMethodCall(MethodCallExpression mc)
at System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node)
at System.Data.Linq.SqlClient.QueryConverter.VisitExpression(Expression
exp)
at System.Data.Linq.SqlClient.QueryConverter.VisitUnary(UnaryExpression u)
at System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node)
at System.Data.Linq.SqlClient.QueryConverter.VisitExpression(Expression
exp)
at System.Data.Linq.SqlClient.QueryConverter.VisitWhere(Expression
sequence, LambdaExpression predicate)
at
System.Data.Linq.SqlClient.QueryConverter.VisitSequenceOperatorCall(MethodCallExpression mc)
at
System.Data.Linq.SqlClient.QueryConverter.VisitMethodCall(MethodCallExpression mc)
at System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node)
at System.Data.Linq.SqlClient.QueryConverter.VisitSelect(Expression
sequence, LambdaExpression selector)
at
System.Data.Linq.SqlClient.QueryConverter.VisitSequenceOperatorCall(MethodCallExpression mc)
at
System.Data.Linq.SqlClient.QueryConverter.VisitMethodCall(MethodCallExpression mc)
at System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node)
at System.Data.Linq.SqlClient.QueryConverter.ConvertOuter(Expression node)
at System.Data.Linq.SqlClient.SqlProvider.BuildQuery(Expression query,
SqlNodeAnnotations annotations)
at
System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query)
at
System.Data.Linq.DataQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
at System.Linq.SystemCore_EnumerableDebugView`1.get_Items()
the queries out.
This works fine:
var qAllJobDescriptions = from j in dc.Jobs
select j;
var qAllOracleJobCodes = from o in dc.OracleJobCodes
select o.JOBCODE;
GridView_Ex3.DataSource = from j in qAllJobDescriptions
where
!(qAllOracleJobCodes).Contains(j.OracleJobCode)
select j;
This works fine:
var qActiveJobDescriptions = from j in dc.Jobs
where DateTime.Today >= j.StartDate
&& (j.EndDate == null || (DateTime.Today <
j.EndDate.Value.AddDays(1)))
select j;
var qActiveOracleJobCodes ="";
GridView_Ex2.DataSource = (from j in qActiveJobDescriptions
where !(from o in dc.OracleJobCodes
where
DateTime.Today >= o.DATEFROM
&& (o.DATETO == null ||
(DateTime.Today < o.DATETO.Value.AddDays(1)))
select
o.JOBCODE).Contains(j.OracleJobCode)
select new { j.OracleJobCode })
This blows up when I move the where !(....).Contains into its own query.
Seems odd because I did a similar thing in the first example.
:
var qActiveJobDescriptions = from j in dc.Jobs
where DateTime.Today >= j.StartDate
&& (j.EndDate == null || (DateTime.Today <
j.EndDate.Value.AddDays(1)))
select j;
var qActiveOracleJobCodes =from o in dc.OracleJobCodes
where
DateTime.Today >= o.DATEFROM
&& (o.DATETO == null ||
(DateTime.Today < o.DATETO.Value.AddDays(1)))
select o.JOBCODE;
GridView_Ex2.DataSource = (from j in qActiveJobDescriptions
where
!(qActiveOracleJobCodes).Contains(j.OracleJobCode)
select new { j.OracleJobCode })
((System.Exception)((new
System.Linq.SystemCore_EnumerableDebugView<<string>>(((System.Data.Linq.DataQuery<<string>>)(GridView_Ex2.DataSource)))).Items)).StackTrace
at System.Data.Linq.SqlClient.SqlFactory.Member(SqlExpression expr,
MemberInfo member)
at
System.Data.Linq.SqlClient.QueryConverter.VisitMemberAccess(MemberExpression
ma)
at System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node)
at System.Data.Linq.SqlClient.QueryConverter.VisitExpression(Expression
exp)
at System.Data.Linq.SqlClient.QueryConverter.VisitCast(UnaryExpression c)
at System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node)
at System.Data.Linq.SqlClient.QueryConverter.VisitExpression(Expression
exp)
at System.Data.Linq.SqlClient.QueryConverter.VisitBinary(BinaryExpression
b)
at System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node)
at System.Data.Linq.SqlClient.QueryConverter.VisitExpression(Expression
exp)
at System.Data.Linq.SqlClient.QueryConverter.VisitBinary(BinaryExpression
b)
at System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node)
at System.Data.Linq.SqlClient.QueryConverter.VisitExpression(Expression
exp)
at System.Data.Linq.SqlClient.QueryConverter.VisitWhere(Expression
sequence, LambdaExpression predicate)
at
System.Data.Linq.SqlClient.QueryConverter.VisitSequenceOperatorCall(MethodCallExpression mc)
at
System.Data.Linq.SqlClient.QueryConverter.VisitMethodCall(MethodCallExpression mc)
at System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node)
at System.Data.Linq.SqlClient.QueryConverter.VisitSelect(Expression
sequence, LambdaExpression selector)
at
System.Data.Linq.SqlClient.QueryConverter.VisitSequenceOperatorCall(MethodCallExpression mc)
at
System.Data.Linq.SqlClient.QueryConverter.VisitMethodCall(MethodCallExpression mc)
at System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node)
at System.Data.Linq.SqlClient.QueryConverter.VisitContains(Expression
sequence, Expression value)
at
System.Data.Linq.SqlClient.QueryConverter.VisitSequenceOperatorCall(MethodCallExpression mc)
at
System.Data.Linq.SqlClient.QueryConverter.VisitMethodCall(MethodCallExpression mc)
at System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node)
at System.Data.Linq.SqlClient.QueryConverter.VisitExpression(Expression
exp)
at System.Data.Linq.SqlClient.QueryConverter.VisitUnary(UnaryExpression u)
at System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node)
at System.Data.Linq.SqlClient.QueryConverter.VisitExpression(Expression
exp)
at System.Data.Linq.SqlClient.QueryConverter.VisitWhere(Expression
sequence, LambdaExpression predicate)
at
System.Data.Linq.SqlClient.QueryConverter.VisitSequenceOperatorCall(MethodCallExpression mc)
at
System.Data.Linq.SqlClient.QueryConverter.VisitMethodCall(MethodCallExpression mc)
at System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node)
at System.Data.Linq.SqlClient.QueryConverter.VisitSelect(Expression
sequence, LambdaExpression selector)
at
System.Data.Linq.SqlClient.QueryConverter.VisitSequenceOperatorCall(MethodCallExpression mc)
at
System.Data.Linq.SqlClient.QueryConverter.VisitMethodCall(MethodCallExpression mc)
at System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node)
at System.Data.Linq.SqlClient.QueryConverter.ConvertOuter(Expression node)
at System.Data.Linq.SqlClient.SqlProvider.BuildQuery(Expression query,
SqlNodeAnnotations annotations)
at
System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query)
at
System.Data.Linq.DataQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
at System.Linq.SystemCore_EnumerableDebugView`1.get_Items()