Error: Setting load options is not allowed after results have been returned from a query

Error: Setting load options is not allowed after results have been returned from a query

Old forum URL: forums.lhotka.net/forums/t/7556.aspx


Pieter posted on Wednesday, September 02, 2009

Hi All,

I've created a sample app using Northwind's Customer, Order, OrderDetails tables. Created a simple EditableRootList for Customer, but when I try and load the Customer list, I get the following error:

DataPortal.Fetch failed (DataPortal.Fetch failed (Setting load options is not allowed after results have been returned from a query.))

Any help would be appreciated.

Thanks!

RockfordLhotka replied on Wednesday, September 02, 2009

That exception text sounds like it comes from some data layer thing (TableAdapter, ADO.NET, etc).

You should look at the full exception text, there's probably more detail about 2 lines into it that will tell you the full exception and the line on which it occurred.

Failing that, put a breakpoint in your DataPortal_Fetch() method and walk through it to see where your code is broken.

ajj3085 replied on Friday, September 04, 2009

Sounds like you're using linq2sql. In L2S, you can set LoadOptions on the DataContext, so that you can do things like load "child' tables with the parent row, so everything is returned all in one big (messy) query (fortunatly the messy query is built by linq, so no need to worry about it usually).

Anyway.. once you do any kind of select using linq, you can't set those load options again. What's happening is your setting them at some point AFTER you've already done a select.. easy to do if you're also using the ContextManager from csla, because usually you can forget about whether or not you have gotten a "new" context or are re-using an exisitng one.

Do a search for DataLoadOptions in your code, and then trace the order of the calls that gets there.

Copyright (c) Marimer LLC