Skip to content

Infragistics Community Forum / Web / Ignite UI for jQuery / A circular reference was detected while serializing an object of type System.Data.Entity.DynamicProxies

A circular reference was detected while serializing an object of type System.Data.Entity.DynamicProxies

New Discussion
Muhammad Shoaib Sidd
Muhammad Shoaib Sidd asked on Jul 15, 2015 10:18 PM

I am getting A circular reference was detected while serializing an object of type ‘System.Data.Entity.DynamicProxies.ApplicationVersion_5873625B844CCA17E07B250096A709DE10780528E07321E64961938506A2A18E’. on cshmle line .Grid(Model)

Below is my code. Please let me know if you need any other information/code sample in order to answer my question.

@using Infragistics.Web.Mvc
@model IQueryable<OTModel.ApplicationVersion>

@(Html.Infragistics()
    .Grid(Model)
    .ID("Grid")
    .Height("500px")
    .Width("100%")
    .AutoGenerateColumns(false)
    .AutoGenerateLayouts(false)
    .RenderCheckboxes(true)
    .PrimaryKey("ApplicationVersionID")
    .Columns(column =>
    {
        column.For(x => x.ApplicationVersionID)
            .HeaderText("Version ID")
            .Width("10%");

        column.For(x => x.VersionName)
            .HeaderText("Version Name")
            .Width("50%");

        column.For(x => x.IsActive)
            .HeaderText("Is Active")
            .Width("25%");
    })
    .Features(feature =>
    {
        feature.Updating().ColumnSettings(cs =>
        {
            cs.ColumnSetting()
                .ColumnKey("ApplicationVersionID")
                .ReadOnly(true);

            cs.ColumnSetting()
                .ColumnKey("VersionName")
                .Required(true)
                .TextEditorOptions(o =>
                    o.ValidatorOptions(vo =>
                        vo.MinLength(4)
                          .KeepFocus(ValidatorKeepFocus.Never)));

            cs.ColumnSetting()
                .ColumnKey("IsActive")
                .Required(true);
        });

        feature.Sorting();
    })
    .DataSourceUrl(Url.Action("GetApplicationVersions"))
    .UpdateUrl(Url.Action("OrdersSaveData"))
    .DataBind()
    .Render()
)
//CONTROLLER

ApplicationVersion av = OTControlPanelBL.GetApplicationVersionByApplicationID(id).AsQueryable();
return View(av);
//Above return list of records, in the above case 4 records

 

Sign In to post a reply

Replies

  • 0
    Muhammad Shoaib Sidd
    Muhammad Shoaib Sidd answered on Jul 2, 2015 7:29 PM

    I am sorry that post doesn't help me.

    If you see in my controller code there is no JSON call/code, that method is a ActionResult for Edit. If you can exactly point out the issue in code then I would be very thankful considering that I am very new in JSON.

    Just to recap. I would like to bind the data to a Editable Infragistics gird. Data is returning from my business layer using EF. My ViewModel is composed of two objects (Header and Detail). I am binding detail object to the grid.

    Thanks 
    Shoaib 

  • 0
    Petko Zhekov
    Petko Zhekov answered on Jul 3, 2015 2:32 PM

    Hi Muhammad,

    Can you send us a small project with sample data which demonstrates the issue. This will helps us debug it and find you a solution quickly.

    We're looking forward to your reply! 

    Kind regards,
    Petko Zhekov
    Software Developer

  • 0
    Muhammad Shoaib Sidd
    Muhammad Shoaib Sidd answered on Jul 7, 2015 5:43 PM

    Can you please provide some direct email address so that I can share files there ? 

  • 0
    Muhammad Shoaib Sidd
    Muhammad Shoaib Sidd answered on Jul 7, 2015 8:15 PM

    I am able to resolve the circular reference issue so at least website is not giving runtime error but still my iggrid doesn’t show any data. Below commented line is the culprit for circular reference.

    //.Grid(Model.ApplicationVersion).Grid<ApplicationVersion>()

    Please download the sample project from the following link (1drv.ms/1KQ5ANe). This is a very simple Master(Applications) and Detail(Application Version) page. Please follow the below steps to setup the project and regenerate the issue

    1. Restore the DB, (OTTestDB.bak)
    2. Open the solution in VS 2013. Enter the password for the OTTestDBEntities connection string in web.config
    3. Click on Applications Menu and edit first record

    You will see a page with some header info but no detail data in iggird. Right now I am just trying to bind some records to the grid. Ultimatly I want to give the same functionalities to my grid which are available on http://www.igniteui.com/grid/basic-editing

    I would really appreciate if you can identify the issue in my project and add some basic functionality to it.

    Regards

    Shoaib

  • 0
    [Infragistics] Michael H.
    [Infragistics] Michael H. answered on Jul 8, 2015 4:22 PM

    Hi Shoaib,

    Thank you for the sample.  The igGrid serializes the EF data internally into JSON, this is why I brought up the JSON serializer earlier.

    You will notice the Circular Reference error shows up during the JsonSerializer calls in the stack trace.  To resolve this, you need to prevent the Serializer from using the Navigation properties in your Entity model.  You can do this by setting the ScriptIgnore attribute on one of the Navigation properties.

    I recommend doing this in your ApplicationVersion class since you have a many-to-one relationship this way.  You can do this by adding the ScriptIgnore attribute to the Application property in ApplicationVersion.cs with the following code:

    using System.Web.Script.Serialization;

    [ScriptIgnore(ApplyToOverrides = true)]
    public virtual Application Application { get; set; }

    Please also note, that since you are manually editing an EF generated file, if the file is regenerated you will need to manually add this attribute again.

    If you need further assistance with this, please let me know and I will be glad to help.

  • 0
    Muhammad Shoaib Sidd
    Muhammad Shoaib Sidd answered on Jul 8, 2015 7:21 PM

    Hi Michael,

    Can you please suggest why the grid is not showing up ?

    Thanks

    Shoaib

  • 0
    [Infragistics] Michael H.
    [Infragistics] Michael H. answered on Jul 8, 2015 10:44 PM

    Hi Shoaib,

    The data is not displaying in the grid because of the Circular Reference exception.  Changing ".Grid(Model.ApplicationVersion)" to ".Grid<ApplicationVersion>()" does not resolve any issues in this scenario, but instead it just sweeps the exception under the rug.  Using ".Grid<ApplicationVersion>()" allows the GET request to return to the client, and the basic layout of the grid (headers, add new row, etc.) is rendered.  Then, the grid makes an AJAX call to its DataSourceUrl to get the rows and this is where the data is serialized and throws the Circular Reference exception.  If you capture your Network traffic, you will see that the call to "/Applications/GetApplicationVersions" returns a 500 error with the Cicrular Reference exception.

    If you modify your EF code with the suggestion from my previous update, this will resolve the Circular Reference exception and you can use either ".Grid(Model.ApplicationVersion)" or ".Grid<ApplicationVersion>()".

    If you have any further questions or concerns with this, please let me know and I will be glad to help.

  • 0
    Muhammad Shoaib Sidd
    Muhammad Shoaib Sidd answered on Jul 9, 2015 10:47 PM

    Hi Micheal,

    I already update the suggested code in EF but the result is same. When I check the network traffic it is giving a different error "Uncaught TypeError: $(…).igGrid is not a function"

    Is it possible for you to update my sample code and share. 

    Regards

    Shoaib

  • 0
    [Infragistics] Michael H.
    [Infragistics] Michael H. answered on Jul 10, 2015 4:48 PM

    Hi Shoaib,

    The cause of that error is due to the scripts you are referencing.

    In _Layout.cshtml, you are rendering your jQuery 1.10.2 scripts at the bottom of the page.  Normally, this would cause a “$ is undefined” error on your Edit page, but you also have jQuery 1.9.1 defined at the top of Edit.cshtml.  You then include the Ignite UI scripts which apply our widgets to jQuery 1.9.1.  Then, the page pulls in the second reference to jQuery 1.10.2 (from _Layouts.cshtml) and overwrites the Ignite UI widgets, which causes the “Uncaught TypeError: $(…).igGrid is not a function” error.

    The solution to this is to reorganize the scripts you are referencing on the page.  I would recommend moving “@Scripts.Render(“~/bundles/jquery”)” in _Layouts.cshtml to the top of the page, under where you render modernizr.  I also recommend removing your reference to jQuery 1.9.1 in Edit.cshtml.  I have attached the modified version of your sample to demonstrate all of my suggested changes.

    If you have any further questions or concerns with this, please let me know.

  • 0
    Muhammad Shoaib Sidd
    Muhammad Shoaib Sidd answered on Jul 13, 2015 4:23 PM

    Thanks Micheal. Now at least I am able to see the grid and its data. Hopefully achieving rest of the grid features would not be that painful.

    One small question, is it possible to hit breakpoint in controller for the jQuery call ?

    Regards

    Shoaib

  • 0
    [Infragistics] Michael H.
    [Infragistics] Michael H. answered on Jul 14, 2015 4:08 PM

    Hi Shoaib,

    I am glad I was able to help.

    I am not entirely sure what breakpoint you are referring to.  If you are referring to the breakpoint in ApplicationsController.GetApplicationVersions(), this gets called when you are using ".Grid<ApplicationVersion>()" in the igGrid.  If you are using ".Grid(Model.ApplicationVersion)" the data is sent to the igGrid during the initial GET of the page, so ApplicationsController.GetApplicationVersions() is never called since the grid already has the data it needs (from Model.ApplicationVersion).

  • 0
    Muhammad Shoaib Sidd
    Muhammad Shoaib Sidd answered on Jul 15, 2015 7:04 AM

    Hi,

    While saving the data of a new row, I need a value of a parameter which is available in a hidden variable (ApplicationID) which is my master record.

    • Is there any option that, I can pass this hidden value as a parameter to my UpdateUrl method so that I can use it while saving the new record in DB? OR
    • Is there any option that, the moment I hit add new row at that time I will save my required parameter value a in a hidden column so that I can get it as t.row.ApplicationID

    In my scenario I have auto increment Primary key, what is the recommended way to handle auto incremented primary key when adding new row. Right now when I hit add row it looks that it takes first missing id from sequence and put it. In actual scenario it should be some empty string and after saving gird should be rebinded, it automatically select the correct primary key data.

    If I need to open a separate thread for it please let me know. 

    Thanks for your help.

    Regards

    Shoaib

  • 0
    [Infragistics] Michael H.
    [Infragistics] Michael H. answered on Jul 15, 2015 10:18 PM

    Hi Shoaib,

    In the future, it would be better to create a new forum post for each new issue.  This helps keep the ideas and solutions better organized.

    For now, I can help with these questions here.  When the igGrid sends its data to the server, it is posting its transactions list.  You can get this list with the allTransactions method.  Then, instead of calling the grid’s saveChanges method, you can manually post the transactions, along with any other data you need to the server.  Then, when that request returns, you should call the dataSource’s _saveChangeSuccess method to let the datasource know the grid data was posted successfully.

    I have attached a simple MVC sample that demonstrates this.  To see this in my sample, edit a row and click the row’s Done button to post the data from the editRowEndedHandler function.

    If you need your ApplicationID to be different based on each row, it would be better to add a hidden bound column.  Then, you can edit this value when needed and it will post back to the server automatically with the transactions.

    As for working with primaryKeys with adding rows, please see our documentation here for the recommended approach:

    http://www.igniteui.com/help/iggrid-updating#adding-primarykey

    If you have any further questions or concerns with this, please let me know and I will be glad to help.

    Attachments:
  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
Muhammad Shoaib Sidd
Favorites
0
Replies
14
Created On
Jul 15, 2015
Last Post
10 years, 7 months ago

Suggested Discussions

Created on

Jul 15, 2015 10:18 PM

Last activity on

Feb 25, 2026 9:18 AM