This is a migrated thread and some comments may be shown as answers.

Grouping and EF 5 Includes

0 Answers 16 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Leontin
Top achievements
Rank 1
Leontin asked on 02 Nov 2012, 10:30 AM
Hi,


I use EF 5 with the "Include" statement such as:

public ActionResult List([DataSourceRequest] DataSourceRequest request)
{
    ... initialize context...
    context.Configuration.ProxyCreationEnabled = false;
    IQueryable<User> set = context.Set<User>().Include(u => u.Country);

    return Json(set.ToDataSourceResult(request));
}

(In order to avoid erros such as "circular reference", I had to disable EF proxy creation.)

The grid works fine until the user starts grouping the columns, at which point the included objects are null, causing the JS to fail and not display the expected data any more.

If I enumerate the source to memory prior to converting to DataSourceResult, it works, the includes are present:

public ActionResult List(DataSourceRequest request)
{
     ... initialize context...
     context.Configuration.ProxyCreationEnabled = false;
     IQueryable<User> set = context.Set<User>().Include(u => u.Country);

    set.ToArray().AsQueryable(); // if I do this it works with Groups...

     return Json(set.ToDataSourceResult(request));
}

How can I make it work without enumerating the data source in memory first? I do not want to use model projection if possible to avoid the 'Include".


Thank you,
Lusu

No answers yet. Maybe you can help?

Tags
Grid
Asked by
Leontin
Top achievements
Rank 1
Share this question
or