1

This question has been completely edited to actually outline the root issue after further investigation.

I was having trouble with no navigation properties appearing on my client side metadata. With deeper inspection of the breeze client side code, I've worked out that the following code in parseCsdlNavProperty (line 6181) is causing all my collection navigation properties to be ignored:

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");
    //}
}

The property referentialConstraint is undefined, and this causes breeze to ignore my related entites. Problem is I'm not sure a) why this is null, b) what this does, c) why breeze seems to hate this, when entity framework seems to be mapping things fine, d) how to fix it.

So I've removed my entire metadata and examples of my model because it's just too much information. If there is information required, just let me know and I'll add it.

Hopefully this makes the question a little more specific and easier to decipher.

Thanks.

Adam
  • 1,011
  • 1
  • 10
  • 25
  • I can't tell from your post if your are having a problem with creating an entity or querying for one. But... this post is a little too big to digest. What would really help is a stripped down version of the problem that illustrates the issue. The Breeze zip contains a sample called Doc code that contains a number of unit tests against EF models. If you can repro your issue within this framework, it is highly likely that we can suggest a solution. – Jay Traband Jun 18 '13 at 06:19
  • I'll have a quick look at the sample and see if I can reproduce the issue. I thought that might be a little too much information, apologies. Essentially if you look at the metadata there are various navigation properties described, but when I either query the metadata on the client side, or try and create an entity, the entities apparently have no navigation properties. (Check the example right at the bottom of the post for creating an ExternalTransactionDataSet - metadata shows navigational properties - entity has none) – Adam Jun 18 '13 at 06:30
  • So more research and so far I can only get navigation properties to work if I include the inverse key as a property on the objects. This looks like its related in some way to http://stackoverflow.com/questions/16797195/child-entities-not-populated-without-inverse-property. Or is there some requirements we must adhere to when creating uni-directional mappings? – Adam Jun 18 '13 at 09:22
  • You do need to identify the ForeignKeys but unidirectional navigations are supported with the latest version of Breeze ( v1.3.5). Could you post your metadata? Or better yet create a small model that shows the issue and post that metadata :) – Jay Traband Jun 18 '13 at 15:50
  • The question is identify the foreign keys how? EF allows me to have a simple ICollection property on one end, and nothing on the other and it will establish the navigation property (and include the foreign key in the schema). But breeze doesn't notice it unless I actually include a foreign key property (not just map). ie: I can map with HasMany(objectx).WithRequired/Optional.Map(m => m.MapKey(..)) but it won't notice it - however if I actually include a property on objectx called parentId (and now I don't actually need to map this, just let EF do it's thing) breeze suddenly starts noticing. – Adam Jun 18 '13 at 20:23

1 Answers1

2

The only reason that you would be missing referential constraints in your model is if 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

Jay Traband
  • 17,053
  • 1
  • 23
  • 44
  • Ok yes I didn't see the bubble on the navigation properties that breeze requires foreign keys for associations. I think in my case there's a disconnect between what's meant by uni-directional relationships. I prefer to not have anything on the child to identify the other end of the relationship because it becomes an issue to manage the integrity of that id. But obviously it is clear on that page that breeze requires it. I would suggest there's a console or some other debug message to explain why it's being ignored. – Adam Jun 19 '13 at 07:54