Connecting EF Data to Grid "circular reference" error

5 posts, 0 answers
  1. Bob
    Bob avatar
    8 posts
    Member since:
    Jun 2012

    Posted 21 Nov 2012 Link to this post

    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
  2. Bob
    Bob avatar
    8 posts
    Member since:
    Jun 2012

    Posted 21 Nov 2012 Link to this post

    Looks like this article addresses it...
    How Do I Avoid Circular Reference?
  3. Rene
    Rene avatar
    65 posts
    Member since:
    Nov 2010

    Posted 18 Jan 2013 Link to this post

    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
  4. Chris
    Chris avatar
    8 posts
    Member since:
    Jan 2012

    Posted 02 Dec 2013 Link to this post

    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?
  5. Bob
    Bob avatar
    8 posts
    Member since:
    Jun 2012

    Posted 03 Dec 2013 Link to this post

    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.
Back to Top