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

[Solved] Ajax binding failing with LinqToSql objects

1 Answer 48 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jose
Top achievements
Rank 1
Jose asked on 29 Aug 2011, 08:29 PM
Hello.

i have this object that i created with LinqToSql

Employee
- ID
- Name
- DateOfBirth
- CompanyMainID -> this is where the problem occurs. LinqToSql creates a collection of CompanyMain in this object.

When i return the collection as the Model to the View (NOT USING AJAX)
IEnumerable<Employee> employee = ctx.Employee.ToList()
View(employee)
and use this in my GRID
@model IEnumerable<Employee>
@(Html.Telerik().Grid(Model)
.Name("Grid")
.Columns(columns=>
{
columns.bound(o=>o.Name);
columns.bound(o=>o.DateOfBirth);
})....etc etc

it works perfect.

when i try to incorporate ajax the Grid

[GridAction]
public ActionResult _AjaxBinding(){
IEnumerable<Employee> employees;
using(DataContext ctx = new DataContext)
{
employees = ctx.Employee.ToList()
}
 
return View(new GridModel<Employee>(){
Data=employees
});
}

THE VIEW and GRID

@model GridModel<Employee>
@(Html.Telerik().Grid<Employee>()
.Name("Grid")
.Columns(columns=>
{
columns.bound(o=>o.Name);
columns.bound(o=>o.DateOfBirth);
})
.DataBindings(b=>b.Ajax().Select("_AjaxBinding","Home"))
....etc etc

goes all the way in the collection of Employees and tries to pull the collection of companies. Of course this throw an exception since the DataContext has been already disposed and can't pull that collection.
Does anyone have come across this issue before?

Thanks

 

 

1 Answer, 1 is accepted

Sort by
0
Jose
Top achievements
Rank 1
answered on 29 Aug 2011, 10:00 PM
I found the answer....

this link
http://blogs.microsoft.co.il/blogs/bursteg/archive/2007/10/06/linq-to-sql-deferred-loading-lazy-load.aspx

DeferredLoadingEnabled must be set to false in order for the Grid not to trigger the properties tied to collections of other objects.

so all i did was

using(DataContext ctx = new DataContext)
{
ctx.DeferredLoadingEnabled = false;
' rest of the code
}

Good Programming y'all!!!

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