开发者

"Calling 'Read' when the data reader is closed is not a valid operation.", but only on one of the Include paths

I'm using the Entity Framework in C# with a MySQL back-end. Here's the problem section of the code:

using (var entities = new myEntities()) {
    Parties = new ObservableCollection<t_party>(
        entities.SalesParties
            .Include("SalesReps")
            .Include("InventoryReservation")
            .Include("InventoryReservation.InventoryAssignment")
            .Include("InventoryReservation.InventoryAssignment.Inventory")
            .ToList()
    );
}

When the code runs, I get an error: "Calling 'Read' when the data reader is closed is not a valid operation." The interesting part is that if I remove the .Include("SalesReps") it works just fine. SalesReps and InventoryReservation are both 0..1 multiplicity from the SalesParty end and * from the other end.

I'm using the Entity Framework 4.1 with the "MySQL Connector Net 6.3.7" library. I tried 6.4.x initially, but ran into some other problems between it and the Entity Framework and had to roll back.

The truly mystifying thing is that I recently switched laptops, and it was running fine on the old one! The old one was running Windows 7 on a 32-bit processor, the new one is 64-bit. Not sure if that would affect things by using different libraries, but it's the onl开发者_开发知识库y other variable I can think of.


I also got the same issue and found that once the using block has been executed, the entities variable will be disposed. So if you try to use it again outside of the block, you will get this error. To solve this problem create entities variable without any using block and then try to run the code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜