Reputation: 83
i get some problem using Breeze to execute queries via my ASP.NET web api application.
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
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"
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 !
Upvotes: 1
Views: 230
Reputation: 83
Thanks !
i added :
[DataMember]
public System.Nullable<int> ParentId { get; set; }
and it works fine now.
Upvotes: 1
Reputation: 526
Breeze needs a foreign key in order to fix up the relations between entities and you're missing it in your Subject class definition:
[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:
[DataMember]
[ForeignKey("FKParentId")]
public Subject Parent { get; set; }
You could also define it via Fluent Interface. You will find more on that at http://msdn.microsoft.com/en-us/data/hh134698.aspx.
Upvotes: 1