Farvashani Farvashani - 8 months ago 24
JSON Question

Breeze does not replace the Ref: node with its real data

How to force breeze to load the real Node data instead of something like

Object {$ref: "5"}
This happens all the time except for one of my extended properties that I created in my Client side code.

The raw JSON has this part:

CurrentUserAssignments: [
$ref: "5"

which never gets referred to the node 5, which is also included in raw JSON results.

Here is part of my EF Entity:

public class Task
public Guid Id {get; set;}

private ICollection<Assignment> _assignments;
public virtual ICollection<Assignment> Assignments
get { return _assignments ?? (_assignments = new Collection<Assignment>()); }
set{_assignments = value;}

public Assignment CurrentUserAssignments
var userId = Guid.Parse(HttpContext.Current.User.Identity.Name.Split('$'[1]);
return Assignments.OrderByDescending(a=>a.AssignmentDate).Take(1).SingleOrDefault(p => p.AssigneeId == userId && p.IsRevoked == false && p.Invisible == false);


and in the client I registered the CurrentUserAssignments in Task Constractor
something like:

store.registerEntityTypeCtor(models.entityNames.task, function () { this.NoteCount = 0; this.IsDone = false; this.CurrentUserAssignments = ko.observable() });

but CurrentUserAssignments is never get full with real data but only


You should use .extend on client or .Include on server side for real data. When server returns $ref, that means that the object has been sent before and it has been given an unique identifier.

Instead of sending same object over and over again, server knows there is an object with unique identifier and can then just send $ref instead of real object. Breeze is capable of parsing this and can replace $ref with real object that has been sent before.

The only thing you need to do is ask breeze to include that object into "main" object using either .expand or .Include on client or server side.

You can read some details about $ref in breeze here: http://breeze.github.io/doc-cs/webservice-data-mapping.html

Just search for $ref, there is description below.