Error: S0133: Implement QueryMethod Queryable.Cast

64 views
Skip to first unread message

Watermelons

unread,
Mar 10, 2010, 10:17:33 PM3/10/10
to DbLinq
I have a table called Events and one called Staff and a linking table
called EventStaff. I create a new EventStaff object and try to assign
an existing Staff record to it. I get an exception when I hit this
code:

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?

Anders

unread,
Mar 11, 2010, 5:25:11 AM3/11/10
to DbLinq
On Mar 11, 4:17 am, Watermelons <danebank.sch...@gmail.com> wrote:
> I have a table called Events and one called Staff and a linking table
> called EventStaff. I create a new EventStaff object and try to assign
> an existing Staff record to it. I get an exception when I hit this
> code:
>
> 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.

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

Jonathan Pryor

unread,
Mar 11, 2010, 8:30:12 AM3/11/10
to dbl...@googlegroups.com
On Wed, 2010-03-10 at 19:17 -0800, Watermelons wrote:
> I have a table called Events and one called Staff and a linking table
> called EventStaff. I create a new EventStaff object and try to assign
> an existing Staff record to it. I get an exception when I hit this
> code:
>
> 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.

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


Watermelons

unread,
Mar 14, 2010, 7:00:55 PM3/14/10
to DbLinq
Thanks for your help guys,

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.

Anders

unread,
Mar 14, 2010, 8:20:19 PM3/14/10
to DbLinq
Ah, just noticed that it's Queryable.Cast (not just any Cast). So the
casts in the where clause was probably not the problem, instead remove
the "Edu.Staff" from the from-clause of the query expression. At least
I could reproduce the exception like this:
var t = (from Employees e in nwind.Employees
select e).ToList();
--
Anders

Watermelons

unread,
Mar 14, 2010, 9:58:12 PM3/14/10
to DbLinq
That does it. I didn't realise it was trying to cast the result entity
to the type specified. I usually specify the type rather than using
object because I though Intellisense would not autocomplete the
properties of the entity unless I gave it a type, but after removing
Edu.Staff I can see that is does.

Thanks for your help.

Sam.

DanM

unread,
May 12, 2010, 3:02:30 PM5/12/10
to DbLinq
I think I'm running into this same problem with this generic
repository method:

public IQueryable<TEntity> GetAll()
{
return Table.Cast<TEntity>();
}

If the entities are of type "Person" and Person implements the IPerson
interface (Person : IPerson), it won't let me cast from Table<Person>
to Queryable<IPerson>. It compiles, but I get the same runtime error
as Watermelons (S0133: Implement QueryMethod Queryable.Cast).

Can you suggest a workaround for this?

Thanks.

--
You received this message because you are subscribed to the Google Groups "DbLinq" group.
To post to this group, send email to dbl...@googlegroups.com.
To unsubscribe from this group, send email to dblinq+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/dblinq?hl=en.

Reply all
Reply to author
Forward
0 new messages