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

Connecting EF Data to Grid "circular reference" error

4 Answers 230 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bob
Top achievements
Rank 1
Bob asked on 21 Nov 2012, 04:51 PM
So I have a grid that is populated from EF5
@model IEnumerable<HCS.Model.FinancialInstitution>
@(Html.Kendo().Grid(Model)
                .Name("Grid")
                .Columns(columns =>
                {
                    columns.Bound(p => p.ID).Visible(false);
                    columns.Bound(p => p.MainRT).Title("RT").Groupable(false);
                    columns.Bound(p => p.LegalName).Title("FI Name");
                })
                .Sortable()
                .Scrollable()
                .Filterable()
                .Selectable()                              
                .DataSource(dataSource => dataSource
                            .Ajax()
                            .ServerOperation(false))
                             
)
I recently added a new table to the database that has a FK to the FinancialInstitution table
I updated the model and the association and navigation are now present.

However, now I get the following error:

"A circular reference was detected while serializing an object of type 'System.Data.Entity.DynamicProxies.FinancialInstitution_1..."
 
I have found a few articles suggesting the disabling of proxy creation, but this doesn't seem to help.
public ActionResult Grid()
        {
            context.Configuration.ProxyCreationEnabled = false;
            var model = context.FinancialInstitutions.ToList();
            return View();
        }
 I also found a blog that suggests a workaround however, I am confused as to whether or not I will have to do something every time a call is made to EF to rewire the JSON results

4 Answers, 1 is accepted

Sort by
0
Bob
Top achievements
Rank 1
answered on 21 Nov 2012, 06:38 PM
Looks like this article addresses it...
How Do I Avoid Circular Reference?
0
Rene
Top achievements
Rank 1
answered on 18 Jan 2013, 02:38 PM
There's another way of handling this.

Base your EF model on a DB View as opposed to a table - where your view has all the data flattened out.

I
0
Chris
Top achievements
Rank 1
answered on 02 Dec 2013, 09:11 PM
Hi Bob,

I'm coming into this a bit late (and am new to both MVC and Kendo; finally moving from Web Forms).. I have virtually the exact error you describe. I also tried disabling proxy creation to no avail. I also created a ViewModel rather than binding directly to the domain model but it didn't change anything.

Wondered if you solved this?
0
Bob
Top achievements
Rank 1
answered on 03 Dec 2013, 01:22 PM
I solved it by creating a model with the data "flattened out".

The post above using a db view wasn't there when I solved the problem or I might have used that approach.
Tags
Grid
Asked by
Bob
Top achievements
Rank 1
Answers by
Bob
Top achievements
Rank 1
Rene
Top achievements
Rank 1
Chris
Top achievements
Rank 1
Share this question
or