MVC 4, Upshot loop references

I have a DbDataController that provides a list of hardware.

public IQueryable<BettrFit.Models.Equipment> GetEquipment() { var q= DbContext.EquipmentSet.OrderBy(e => e.Name); return q; } 

In my subclass, everything looks fine.

But the equipment contains a member of the HashSet EquipmentType. I want to show this type in my view, and also be able to add data to the EquipmentType collection of equipment (through a list of several types).

But if I try to include "EquipmentType" in my linq query , it fails during serialization .

  public IQueryable<BettrFit.Models.Equipment> GetEquipment() { var q= DbContext.EquipmentSet.Include("EquipmentType").OrderBy(e => e.Name); return q; } 

"The object graph for the EquipmentType type contains loops and cannot be serialized if link tracking is disabled"

How to enable "reverse link tracking"?

Maybe the problem is that EquipmentType supports feedback through a HashSet? But I do not include ("EquipmentType.Equipment") in my request. So it should be good.

How does upshot generate a model? I just found the EquipmentViewModel.js file, but it does not contain any model members.

Here are my model classes:

 public class Equipment { public Equipment() { this.Exercise = new HashSet<Exercise>(); this.EquipmentType = new HashSet<EquipmentType>(); this.UserDetails = new HashSet<UserDetails>(); } public int ID { get; set; } public string Name { get; set; } public string Description { get; set; } public string Picture { get; set; } public string Link { get; set; } public string Producer { get; set; } public string Video { get; set; } public virtual ICollection<EquipmentType> EquipmentType { get; set; } public virtual ICollection<UserDetails> UserDetails { get; set; } } public class EquipmentType { public EquipmentType() { this.Equipment = new HashSet<Equipment>(); this.UserDetails = new HashSet<UserDetails>(); } public int ID { get; set; } public string Name { get; set; } public string Description { get; set; } public virtual ICollection<Equipment> Equipment { get; set; } public virtual ICollection<UserDetails> UserDetails { get; set; } } 
+1
asp.net-mvc razor upshot
source share
4 answers

I figured out, in part, how to solve a circular reference problem.

I just repeated my requested collection (using Include ()) and set the backlinks to the parent in NULL. This worked on a serialization issue that otherwise already breaks on the server.

The only problem now in updating the data object is its failure, because the arrays of the referenced array of objects are static ...

0
source share

try decorating one of the navigation properties with [IgnoreDataMember]

 [IgnoreDataMember] public virtual ICollection<Equipment> Equipment { get; set; } 
+2
source share

A model created using upshot can be found on the page itself. In the Index view, you will see the HTML UpshotContext (given that you are using the latest version of SPA), which indicates the data type and model type.

When the page is displayed in the browser, this helper code is replaced by the actual model definition. To see this, browse the source code of your page in a browser and find the <script> tag that starts with upshot.dataSources = upshot.dataSources || {}; upshot.dataSources = upshot.dataSources || {};

Check here for more information on how upshot creates a client model. As for the "backlink to links," I do not know :)

0
source share

To solve a circular backlink, you can use the IgnoreDataMember attribute. Or you can set a null trackback before returning data from the DbDataController

I posted a working solution for your problem in another question, but first used the Entity Framework Code. stack overflow

Here I will show how to create my client model manually, allowing you to map data, but please

0
source share

All Articles