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

[Solved] MVC Grid, View models and many to many relationships

1 Answer 86 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.
Michael
Top achievements
Rank 1
Michael asked on 05 Mar 2012, 01:11 PM
Hi everyone,

We would like to use the MVC Grid in our application but we face some problems :

We are use EF 4 Code first. We have some object that have some relationships to intermediate object and this intermediate table has a link to the other end of the relationship.

For example :

We have an object Study

public class Study
{
     public int Id;
     public virtual ICollection<StudyGroup> StudyGroups;
     // Class simplified for clarity
}

Class StudyGroup

public class StudyGroup
{
     public int Id;
     public virtual Study Study;
     public virtual Group Group
}

and the class Group :

public class Group
{
     public int Id;
     public virtual ICollection<StudyGroup> StudyGroups;
}


Since both end of relation has a navigation property, this cause cycles when trying to convert to JSON.
How are we supposed to solve this issue ?

Thanks

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 08 Mar 2012, 02:29 PM
Hello Michael,

You should use a view model , which doesn't contain the navigation properties, in order to avoid the circular reference exception.

All the best,
Daniel
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
Tags
Grid
Asked by
Michael
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or