entity framework - EF4 - Linq - Exception on Query.Any() -


i've using ef while i've never had problem. have wcf services provide data web front end. in service, use ef 4 data implementation. bypass repository , singleton, simple function below:

using (ourentities datacontext = new ourentities()) {     datacontext.order.mergeoption = system.data.objects.mergeoption.notracking;     list<order> orders = new list<order>();     var query = p in datacontext.order.include("orderdetail")                 (p.orderid == orderid || orderid == 0)                    && (p.orderstatus == orderstatus || orderstatus == 0)                    && (p.ordertype == ordertype || ordertype == 0)                    && (p.orderflag == null || p.orderflag == false)                 select p;      if (query.any())     {         foreach (order order in query)         {             orders.add(order);         }     }     return orders; } 

orderid, orderstatus & ordertype passed in parameters.
code works without problems, expected... until run few stress tests call services (i.e. functions) simultaneously different clients. after few minutes, bunch of invalidoperationexception: specified cast materialized 'system.int32' type 'system.boolean' type not valid. in our sql 2008 database, orderid int (identity, auto-gen) , orderflag field data type = bit (translated boolean ef).
during debug, found out exception either thrown query.any() or foreach clause, when single item in query casted order. if touch transaction mean (either run same query on ssms or execute query.any() in watch window), query updated proper data , works....
our evironment: vs 2010, .net framework 4, ef 4, sql server 2008 express + standard (i've tried on both)
comments or appreciated...
eric

you should start modifying code to:

using (ourentities datacontext = new ourentities()) {     datacontext.order.mergeoption = system.data.objects.mergeoption.notracking;     var query = p in datacontext.order.include("orderdetail")                 (p.orderid == orderid || orderid == 0)                    && (p.orderstatus == orderstatus || orderstatus == 0)                    && (p.ordertype == ordertype || ordertype == 0)                    && (p.orderflag == null || p.orderflag == false)                 select p;      return query.tolist(); } 

and run tests again. don't except solve problem current code should not pass code review.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -