EF Lazy Loading -> Command out of sync
Posted: Mon 03 Oct 2016 12:30
Hello!
We have been using dotConnect for MySQL version 7.6.217 for a long time. Now we wanted to upgrade to the latest version (8.6.743 at the moment) but got into trouble with lazy loading.
The exception is "Commands out of sync; You can't run this command now" when trying to access a navigation property that has not been loaded with the initial query:
If the initial query includes the navigation property then it works without problems:
We are using Entity Framework 5.0.0 but we have also tested with EF6 and an older version of dotConnect MySql 8.4.616 with the same results.
We have created the model from scratch with database first to make sure we don't have messed up something. So the model (edml) is using all default settings which includes LazyLoading.
Do you have any idea what could be causing this issue?
Regards
Andreas
We have been using dotConnect for MySQL version 7.6.217 for a long time. Now we wanted to upgrade to the latest version (8.6.743 at the moment) but got into trouble with lazy loading.
The exception is "Commands out of sync; You can't run this command now" when trying to access a navigation property that has not been loaded with the initial query:
Code: Select all
using System;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
try
{
var context = new TestDevModel.TestDevEntities();
var orders = context.Orders.Include("OrderEvents.Address");
foreach (var order in orders)
{
foreach (var orderEvent in order.OrderEvents)
{
if (orderEvent.Address != null)
{
// This will throw an exception:
// "Commands out of sync; You can't run this command now"
var type = orderEvent.Address.AddressType;
}
}
}
}
catch (Exception ex)
{
}
}
}
}
Code: Select all
var orders = context.Orders.Include("OrderEvents.Address.AddressType");
We have created the model from scratch with database first to make sure we don't have messed up something. So the model (edml) is using all default settings which includes LazyLoading.
Do you have any idea what could be causing this issue?
Regards
Andreas