Edu.EventStaff newEventStaff = new Edu.EventStaff();
newEventStaff.Staff =(from Edu.Staff staffMember
in EduDContext.Staff
where staffMember.ContactID ==
(int)currentBooking.EduContactID
select staffMember).Single();
S0133: Implement QueryMethod Queryable.Cast.
Stack:
at
DbLinq.Data.Linq.Sugar.Implementation.ExpressionDispatcher.AnalyzeQueryableCall(MethodInfo
method, IList`1 parameters, BuilderContext builderContext) in Z:
\Development\DbLinq-0.19\src\DbLinq\Data\Linq\Sugar\Implementation
\ExpressionDispatcher.Analyzer.cs:line 254
at
DbLinq.Data.Linq.Sugar.Implementation.ExpressionDispatcher.AnalyzeCall(MethodCallExpression
expression, IList`1 parameters, BuilderContext builderContext) in Z:
\Development\DbLinq-0.19\src\DbLinq\Data\Linq\Sugar\Implementation
\ExpressionDispatcher.Analyzer.cs:line 178
at
DbLinq.Data.Linq.Sugar.Implementation.ExpressionDispatcher.Analyze(Expression
expression, IList`1 parameters, BuilderContext builderContext) in Z:
\Development\DbLinq-0.19\src\DbLinq\Data\Linq\Sugar\Implementation
\ExpressionDispatcher.Analyzer.cs:line 109
at
DbLinq.Data.Linq.Sugar.Implementation.ExpressionDispatcher.Analyze(Expression
expression, Expression parameter, BuilderContext builderContext) in Z:
\Development\DbLinq-0.19\src\DbLinq\Data\Linq\Sugar\Implementation
\ExpressionDispatcher.Analyzer.cs:line 96
at
DbLinq.Data.Linq.Sugar.Implementation.ExpressionDispatcher.Analyze(ExpressionChain
expressions, Expression parameter, BuilderContext builderContext) in Z:
\Development\DbLinq-0.19\src\DbLinq\Data\Linq\Sugar\Implementation
\ExpressionDispatcher.Analyzer.cs:line 73
at
DbLinq.Data.Linq.Sugar.Implementation.QueryBuilder.BuildExpressionQuery(ExpressionChain
expressions, Expression tableExpression, BuilderContext
builderContext) in Z:\Development\DbLinq-0.19\src\DbLinq\Data\Linq
\Sugar\Implementation\QueryBuilder.cs:line 203
at
DbLinq.Data.Linq.Sugar.Implementation.QueryBuilder.BuildExpressionQuery(ExpressionChain
expressions, BuilderContext builderContext) in Z:\Development
\DbLinq-0.19\src\DbLinq\Data\Linq\Sugar\Implementation
\QueryBuilder.cs:line 182
at
DbLinq.Data.Linq.Sugar.Implementation.QueryBuilder.BuildExpressionQuery(ExpressionChain
expressions, QueryContext queryContext) in Z:\Development
\DbLinq-0.19\src\DbLinq\Data\Linq\Sugar\Implementation
\QueryBuilder.cs:line 76
at
DbLinq.Data.Linq.Sugar.Implementation.QueryBuilder.GetSelectQuery(ExpressionChain
expressions, QueryContext queryContext) in Z:\Development
\DbLinq-0.19\src\DbLinq\Data\Linq\Sugar\Implementation
\QueryBuilder.cs:line 393
at
DbLinq.Data.Linq.Implementation.QueryProvider`1.GetQuery(Expression
expression) in Z:\Development\DbLinq-0.19\src\DbLinq\Data\Linq
\Implementation\QueryProvider.cs:line 165
at DbLinq.Data.Linq.Implementation.QueryProvider`1.Execute[TResult]
(Expression expression) in Z:\Development\DbLinq-0.19\src\DbLinq\Data
\Linq\Implementation\QueryProvider.cs:line 192
at System.Linq.Queryable.Single[TSource](IQueryable`1 source)
at Danebank.EduInterface.InsertBooking() in d:\PACBookingsWebsite
\App_Code\Danebank.Bookings.cs:line 186
at _newBooking.dsLinqBookings_Inserted(Object sender,
LinqDataSourceStatusEventArgs e) in D:\PACBookingsWebsite\book
\Booking.aspx.vb:line 109
at
System.Web.UI.WebControls.LinqDataSourceView.OnInserted(LinqDataSourceStatusEventArgs
e)
at
System.Web.UI.WebControls.LinqDataSourceView.ExecuteInsert(IDictionary
values)
at System.Web.UI.DataSourceView.Insert(IDictionary values,
DataSourceViewOperationCallback callback)
Where am I going wrong?
This error seems to mean that a method called "Cast" is used within
the query expression and that it can not be converted to sql. So my
guess would be, that it is the "staffMember.ContactID ==
(int)currentBooking.EduContactID" part that is causing the problems.
You might double check the data type of "ContactID" or put
"(int)currentBooking.EduContactID" in a temporary variable.
--
Anders
Looks like a bug because Queryable.Cast() isn't specially handled, and
the Queryable.Cast() call comes from the cast in your 'where'
expression.
> Where am I going wrong?
Nothing, it's a bug.
As a workaround, remove the cast. If you can't remove the cast, you
might try using an intermediary (I haven't tested this):
Edu.EventStaff newEventStaff = new Edu.EventStaff () {
Staff = (from Edu.Staff staffMember in EduDContext.Staff
let id = (int) currentBooking.EduContactID
where staffMember.ContactID == id
select staffMember).Single(),
};
I don't know if that will work or not. The real fix is (of course) to
fix the bug in DbLinq.
Thanks,
- Jon
staffMember.ContactID is an int and currentBooking.EduContactID is a
nullable int, so I tried declaring local variable
int currContactID = (int)currentBooking.EduContactID;
then as you pointed out Jon,
Edu.EventStaff newStaff = new Edu.EventStaff()
{
Staff = (from Edu.Staff staffMember in EduDContext.Staff
where staffMember.ContactID == currContactID
select staffMember).Single(),
};
I still get the same exception. Must be a bug in DbLinq, now I just
have to try to figure out how to fix the bug!!
Thanks,
Sam.
Thanks for your help.
Sam.