[英]Breeze - self referencing entity
i get some problem using Breeze to execute queries via my ASP.NET web api application. 使用Breeze通过我的ASP.NET Web API应用程序执行查询时遇到一些问题。
Here is my entity definition that i want to request on : 这是我要请求的实体定义:
[Serializable]
[DataContract]
public class Subject
{
public Subject()
{
Subjects = new List<Subject>();
}
[DataMember]
public int Id { get; set; }
[DataMember]
public String Name { get; set; }
[DataMember]
public Subject Parent { get; set; }
[DataMember]
public IList<Subject> Subjects { get; set; }
}
and here is the query in my datacontext.js file 这是我的datacontext.js文件中的查询
var query = EntityQuery.from("Subjects");
manager.executeQuery(query)
.then(function (data) {
// do something with data.results
})
.fail(function (error) {
});
but the query always fails with an error saying "expected object" 但是查询总是失败,并显示错误消息“ expected object”
All other queries on other "simple" entities works fine. 对其他“简单”实体的所有其他查询都可以正常工作。 If i remove the properties "Parent" and "Subjects" from my Subject Entity, the query works.
如果我从主题实体中删除属性“父母”和“主题”,则该查询有效。
Does anyone have an idea ? 有人有主意吗?
Thanks ! 谢谢 !
Breeze needs a foreign key in order to fix up the relations between entities and you're missing it in your Subject class definition: Breeze需要一个外键来修正实体之间的关系,而您在Subject类定义中将其遗漏了:
[DataMember]
public System.Nullable<int> ParentId { get; set; }
Or, if you are using non-conventional naming, be sure to add the ForeignKey tag to the navigation: 或者,如果您使用的是非常规命名,请确保将ForeignKey标记添加到导航中:
[DataMember]
[ForeignKey("FKParentId")]
public Subject Parent { get; set; }
You could also define it via Fluent Interface. 您也可以通过Fluent接口定义它。 You will find more on that at http://msdn.microsoft.com/en-us/data/hh134698.aspx .
您可以在http://msdn.microsoft.com/zh-cn/data/hh134698.aspx上找到更多相关信息。
Thanks ! 谢谢 !
i added : [DataMember] public System.Nullable<int> ParentId { get; set; }
我添加了:
[DataMember] public System.Nullable<int> ParentId { get; set; }
[DataMember] public System.Nullable<int> ParentId { get; set; }
and it works fine now. 现在可以正常工作了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.