问题
I've updated my client library and server web api dll to latest version.
Now whenever I do an expand on a query, I get that kind of error:
unable to locate property: Mandate on type: MandateHistory:#Dom.DirectDebit
with the query being :
var query = breeze.EntityQuery.from("MandatesHistory")
.where("Mandate.Id", "==", mandatId).expand("Mandate");
return manager.executeQuery(query.using(service));
If I downgrade to 1.3.3 (the client library only), everything works fine.
I would have like to try 1.3.4 or 1.3.5 but I can't find them on the website....
What has changed between 1.3.3 and 1.3.6 that could break my application ?
EDIT
THIS IS THE CODE CAUSING ISSUES :
In 1.3.6, in the function parseCsdNavProperty, the following code was added:
var constraint = association.referentialConstraint;
if (!constraint) {
// TODO: Revisit this later - right now we just ignore many-many and assocs with missing constraints.
return;
// Think about adding this back later.
//if (association.end[0].multiplicity == "*" && association.end[1].multiplicity == "*") {
// // many to many relation
// ???
//} else {
// throw new Error("Foreign Key Associations must be turned on for this model");
//}
}
Basically, for the navigation property MandateHistory.Mandate, there is no contraint found, so the code just return. This is the cause of my issue.
In version 1.3.3, there was no check on constraint because first there was the following check which returns false in my case (isScalar is false):
if (toEnd && isScalar) {
var constraint = association.referentialConstraint;
if (constraint) {
var principal = constraint.principal;
var dependent = constraint.dependent;
var propRefs;
if (csdlProperty.fromRole === principal.role) {
propRefs = toArray(principal.propertyRef);
} else {
propRefs = toArray(dependent.propertyRef);
}
// will be used later by np._update
fkNamesOnServer = propRefs.map(__pluck("name"));
}
}
Can the breeze team look into this ?
SOLUTION
Following Jay's suggestion, the .net model had to be changed in order to explicitly set the foreign key association between MandateHistory and Mandate:
public class MandateHistory
{
[ForeignKey("Mandate")]
public int Mandate_Id { get; set; }
public virtual Mandate Mandate { get; set; }
}
回答1:
My guess is that you are missing referential constraints in your model. i.e. the Entity Framework thinks that you are not exposing foreign keys. See Foreign keys in the Entity Framework.
Breeze requires the foreign keys in order to perform it's automatic object linking logic.
This is also described here: Breeze navigation properties
来源:https://stackoverflow.com/questions/17658128/breezejs-v1-3-6-breaks-my-application