c# - An unhandled exception of type 'System.InvalidCastException' -
my c# vs2015 application throws exception:
system.invalidcastexception unhandled
message=unable cast object of type 'system.data.entity.infrastructure.dbquery`1[adonet4linqtoentities.customer]' type 'system.data.objects.objectquery'.
source=adonet4linqtoentities
the error occurs in line defines query variable:
var customers = c in de.customers c.orders.any(o => o.orderamount > 150) select c; string query = ((objectquery)customers).totracestring();
my assumption objectquery
prompting exception.
i tried string query = ((dbquery)customers).tostring()
instead, works in vs2013, resulted in same exception.
why vs2015 throw exceptions these query approaches?
because customers
not objectquery
want objectquery<customer>
remove projection (the select
).
change to
var customersquery= c in de.customers c.orders.any(o => o.orderamount > 150); string query = customersquery.totracestring();
i took out naming lexical ambiguity naming customersquery
.
see objectquery.totracestring method (system.data.objects) more information.
Comments
Post a Comment