title: MySql 5 & LINQ to Entities EF 4 causing "Object must implement IConvertible" when querying across network
body: <p>When using the same MVC 3 &amp; C# code along with copies of the same MySql 5.5 database on 2 different MySql installations. One works perfectly while the other one fails with an "Object must implement IConvertible" error. When I run the query against my local PC's MySql installation the query always works perfectly, but when I try querying from local PC's Visual Studio 2010 to a copy of the same database at my Internet Service Provider's MySql installation then I receive an error "Object must implement IConvertible". The only thing I change in the code is the ConnectionString's Server Name in the web.config, otherwise the code &amp; database are exactly the same. NOTE: All other queries to the ISP's MySql installation work perfectly only this one particular query doesn't work. </p>
  
  <p>After trying to troubleshoot this for several days I'm convinced that the error message "Object must implement IConvertible" has nothing to do with what is actually happening and I'm also under the impression that the MySql configuration at my ISP may somehow be causing this issue for the following reasons:</p>
  
  <ol>
  <li><p>If this were truly an "Object must implement IConvertible" issue within the code then the issue would persist in the code and happen no matter which DB installation I hit.</p></li>
  <li><p>I've completely dropped &amp; recreated the DB at the ISP from my local PC's working copy however still receive the same exactly error.</p></li>
  <li><p>MOST INTERESTINGLY is that the query has 3 nested IEnumerable lists that are all setup in the same way as IEnumerables and if I comment out any 1 of these nested lists in the query then the query runs successfully against the ISP's DB. It doesn’t matter which nested list gets commented out, only that there are 2 or less nested lists and then the query to the DB at ISP works. This is what leads me to the conclusion that MySql’s configuration at the ISP may be limiting my queries in some way, as I do not have this problem when querying my local PC's MySql installation. The error message really doesn’t appear to apply to what is actually happening. Again, all the other queries to the ISP's MySql installation work perfectly, however none of them contain more than 2 nested IEnumerable lists where this particular query contains 3?</p></li>
  </ol>
  
  <p><strong>Query Error "Object must implement IConvertible"</strong></p>
  
  <pre><code>    Server Error in '/' Application.
      ________________________________________
      Object must implement IConvertible. 
      Description: An unhandled exception occurred during the execution of the current web request.             Please review the stack trace for more information about the error and where it originated in the code. 
  
      Exception Details: System.InvalidCastException: Object must implement IConvertible.
  
      Source Error: 
  
      Line 392:
      Line 393:
      Line 394:            var query =
      Line 395:                  (from p in db.products
      Line 396:                   where p.ClientId == clientId
  
      Source File: C:\Users\JR\Documents\Visual Studio 2010\Projects\Subversion\ReservarMVC\ReservarMVC\Models\ProductRepository.cs    Line: 394 
  
      Stack Trace: 
  
      [InvalidCastException: Object must implement IConvertible.]
      System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider) +9528453
      MySql.Data.Entity.EFMySqlDataReader.ChangeType(Object sourceValue, Type targetType) +566
      MySql.Data.Entity.EFMySqlDataReader.GetValue(Int32 ordinal) +231
      System.Data.Common.Internal.Materialization.ErrorHandlingValueReader`1.GetValue(DbDataReader reader, Int32 ordinal) +215
      System.Data.Common.Internal.Materialization.Shaper.GetColumnValueWithErrorHandling(Int32 ordinal) +46
      lambda_method(Closure , Shaper ) +180
      System.Data.Common.Internal.Materialization.Coordinator`1.ReadNextElement(Shaper shaper) +170
      System.Data.Common.Internal.Materialization.RowNestedResultEnumerator.MoveNext() +235
      System.Data.Common.Internal.Materialization.ObjectQueryNestedEnumerator.TryReadToNextElement() +49
      System.Data.Common.Internal.Materialization.ObjectQueryNestedEnumerator.ReadElement() +29
      System.Data.Common.Internal.Materialization.ObjectQueryNestedEnumerator.MoveNext() +68
      System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +327
      System.Linq.Enumerable.ToList(IEnumerable`1 source) +58
      ReservarMVC.Models.ProductRepository.GetProductList(Nullable`1 dateStart, Nullable`1    dateEnd,         Nullable`1 personQuantityId, Nullable`1 roomQuantityId) in C:\Users\JR\Documents     \Visual      Studio 2010\Projects\Subversion\ReservarMVC\ReservarMVC\Models\ProductRepository.cs:394
      ReservarMVC.Models.ProductRepository.GetProductListSearch(Nullable`1 dateStart, Nullable`1 dateEnd, Nullable`1 personQuantityId, Nullable`1 roomQuantityId) in C:\Users\JR\Documents\Visual Studio 2010\Projects\Subversion\ReservarMVC\ReservarMVC\Models\ProductRepository.cs:605
      ReservarMVC.Controllers.PortalController.MyExcurcion(ProductListSearchVM viewModel) in C:\Users\JR\Documents\Visual Studio 2010\Projects\Subversion\ReservarMVC\ReservarMVC\Controllers\PortalController.cs:63
       lambda_method(Closure , ControllerBase , Object[] ) +162
       System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +17
       System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +208
        System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
        System.Web.Mvc.&lt;&gt;c__DisplayClass15.&lt;InvokeActionMethodWithFilters&gt;b__12() +55
        System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +263
        System.Web.Mvc.&lt;&gt;c__DisplayClass17.&lt;InvokeActionMethodWithFilters&gt;b__14() +19
        System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +191
        System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +343
        System.Web.Mvc.Controller.ExecuteCore() +116
        System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +97
        System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
        System.Web.Mvc.&lt;&gt;c__DisplayClassb.&lt;BeginProcessRequest&gt;b__5() +37
        System.Web.Mvc.Async.&lt;&gt;c__DisplayClass1.&lt;MakeVoidDelegate&gt;b__0() +21
        System.Web.Mvc.Async.&lt;&gt;c__DisplayClass8`1.&lt;BeginSynchronous&gt;b__7(IAsyncResult _) +12
        System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
        System.Web.Mvc.&lt;&gt;c__DisplayClasse.&lt;EndProcessRequest&gt;b__d() +50
        System.Web.Mvc.SecurityUtil.&lt;GetCallInAppTrustThunk&gt;b__0(Action f) +7
        System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22
        System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60
        System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
        System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8967601
        System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously) +184
  
        ________________________________________
        Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.261
  </code></pre>
  
  <p><strong>LINQ-to-Entities Query:</strong></p>
  
  <pre><code>    public IEnumerable&lt;ProductListVM&gt; GetProductList(DateTime? dateStart, DateTime? dateEnd, int? personQuantityId, int? roomQuantityId)
      {
          var query =
                (from p in db.products
                 where p.ClientId == clientId
                 where p.ProductTypeId == 5 
                 where personQuantityId &lt;= p.Capacity
                 where roomQuantityId &lt;= p.Quantity
                 select new ProductListVM
                 {
                     ProductId = p.ProductId,
                     ClientId = p.ClientId,
                     Name = p.Name_en,
                     Title = p.Title_en,
                     Description = p.Description_en,
                     Quantity = p.Quantity,
                     Capacity = p.Capacity,
                     newbookings = from b in db.bookings 
                                   where b.ProductId == p.ProductId
                                   from res in db.reservations
                                   where b.ReseravationId == res.ReservationId
                                   where b.BookingDateTime &gt;= dateStart &amp;&amp; b.BookingDateTime &lt;= dateEnd &amp;&amp; res.ReservationStateId != 3 
                                   select new BookingVM
                                   {
                                       ProductId = b.ProductId,
                                       BookingId = b.BookingId,
                                       ClientId = b.ClientId,
                                       ReservationId = b.ReseravationId,
                                       BookingDateTime = b.BookingDateTime
                                   },                  
                     newratecategories = from prc in db.productratecategories
                                         where prc.ProductId == p.ProductId
                                         from rc in db.ratecategories
                                         where prc.RateCategoryId == rc.RateCategoryId
                                         where (dateStart &gt;= rc.DateStart &amp;&amp; dateEnd &lt;= rc.DateEnd) || (dateStart &gt;= rc.DateStart || dateEnd &lt;= rc.DateEnd)                                           
                                         select new MegaRateCategoryVM
                                         {
                                             RateCategoryId = rc.RateCategoryId,                                               
                                             DateStart = rc.DateStart,
                                             DateEnd = rc.DateEnd                                      
                                         },
                     newproductimages = (from pi in db.productimages
                                         where pi.ProductId == p.ProductId
                                         from ig in db.imagegalleries
                                         where pi.ImageGalleryId == ig.ImageGalleryId
                                         select new MegaProductImageVM
                                         {
                                             ig_Description = ig.ig_Description,
                                             ImageGalleryId = pi.ImageGalleryId
                                         }).OrderByDescending(i =&gt; i.ImageGalleryId)
                 }).ToList();
  
          return query;
      }
  </code></pre>
  
  <p><strong>Product List ViewModel:</strong></p>
  
  <pre><code>    namespace Project.ViewModels
      {
          [Serializable]
          public class ProductListVM : BaseViewModel
          {        
              public int ProductId { get; set; }        
              public int? ClientId { get; set; }
              public int? ProductTypeId { get; set; }
              public int? ProductStateId { get; set; }
              public String Name { get; set; }        
              public String Title { get; set; }
              public String Description { get; set; }
              public int? Quantity { get; set; }
              public int? Capacity { get; set; }        
  
              //PRODUCTIMAGE table fields
              public IEnumerable&lt;MegaProductImageVM&gt; newproductimages { get; set; }
  
              //RATECATEGORY table fields
              public IEnumerable&lt;MegaRateCategoryVM&gt; newratecategories { get; set; }
  
              //BOOKING table fields
              public IEnumerable&lt;BookingVM&gt; newbookings { get; set; }       
  
          }
  
      }
  </code></pre>
  
  <p>What could be causing this behavior? Could this be caused by a query threshold setting or network setting on the MySql 5.5's database configuration? I haven't changed any of the defaults on either of the MySql 5.5 installations. I'm just using the standard MySql Connector/Net 6.5.4 to access the DB along with Microsoft's standard MVC 3, C#, Entity Framework 4, LINQ-to-Entities code. </p>
  
  <p>Any help on this is greatly appreciated. Thanks, Atlas361 </p>