EF Lazy Loading -> Command out of sync

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for MySQL
Post Reply
asten
Posts: 2
Joined: Wed 11 Nov 2015 08:33

EF Lazy Loading -> Command out of sync

Post by asten » 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:

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)
            {
            }
        }
    }
}
If the initial query includes the navigation property then it works without problems:

Code: Select all

var orders = context.Orders.Include("OrderEvents.Address.AddressType");
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

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: EF Lazy Loading -> Command out of sync

Post by Shalex » Thu 06 Oct 2016 14:25

Thank you for your report. We will investigate the issue and notify you about the result.

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: EF Lazy Loading -> Command out of sync

Post by Shalex » Wed 30 Nov 2016 19:16

Please add the "Default FetchAll=true;" option to your connection string to fix the issue. That was a default behaviour with v7.6.217.

Post Reply