Breeze不会用其实际数据替换Ref:节点 [英] Breeze does not replace the Ref: node with its real data
问题描述
如何强制微风加载实际的Node数据而不是诸如Object {$ref: "5"}
之类的数据?
除了我在客户端代码中创建的扩展属性之一以外,这种情况一直都在发生.
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.
原始JSON包含以下部分:
The raw JSON has this part:
CurrentUserAssignments: [
{
$ref: "5"
}
],
从不引用节点5,该节点5也包含在原始JSON结果中.
which never gets referred to the node 5, which is also included in raw JSON results.
这是我的EF实体的一部分:
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;}
}
[NotMapped]
public Assignment CurrentUserAssignments
{
get
{
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);
}
}
....
}
,然后在客户端中,我在Task Constractor中注册了CurrentUserAssignments 像这样:
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() });
但是CurrentUserAssignments永远不会充满真实数据,而只会充满ref:'5'
but CurrentUserAssignments is never get full with real data but only ref:'5'
推荐答案
您应该在客户端使用.extend
或在服务器端使用.Include
来获取真实数据.当服务器返回$ ref时,这意味着该对象已被发送过,并且已被赋予唯一标识符.
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.
服务器知道有一个具有唯一标识符的对象,而不是一遍又一遍地发送相同的对象,因此可以只发送$ ref而不是实际对象. Breeze能够解析此内容,并且可以将$ ref替换为之前发送的真实对象.
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.
您唯一需要做的就是让客户端或服务器端使用.expand或.include轻而易举地将该对象包含到主要"对象中.
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.
您可以在这里轻松阅读有关$ ref的一些详细信息: http: //breeze.github.io/doc-cs/webservice-data-mapping.html
You can read some details about $ref in breeze here: http://breeze.github.io/doc-cs/webservice-data-mapping.html
只需搜索$ ref,下面就有说明.
Just search for $ref, there is description below.
这篇关于Breeze不会用其实际数据替换Ref:节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!