Spontifixus
Spontifixus

Reputation: 6660

How to build One-To-Many relationships with NHibernate for use with Breezejs

I am trying to map a relaitively simple data model with NHibernate for use with breeze.js. The data model consists of four entities and looks like this:

The Data Model

The problem seems to be with the relationship between the CourseDate and the CourseDateStudent entity. When calling the Metdata method of my BreezeController I get the following error:

System.ArgumentException: "Could not find matching fk for property HR.CourseManager.Web.Data.Entities.CourseDateStudent.CourseDate"

I do not know what exactly causes this behavior as I think I have implemented my model as recommended by the breeze.js documentation.

There is another question convering a somewhat similar topic, but this question does not address having composite keys.

(Remark: Adding surrogate keys like numeric ids is not an option here. As you might have guessed this is not the real data model but one that simply has had its entities renamed. The underlying database is used by a whole bunch of applications and cannot be changed.)


Enough of writing about my problem. Let's see some code! So there is the CourseDate entity which has a composite key consisting of the properties CourseCode and Date:

And then there is the CourseDateStudent entity that has a primary key consisting of the CourseCode and the CourseDate property (thus defining the foreign key relationship to the CourseDate entity) as well as the StudentId property:

Upvotes: 0

Views: 255

Answers (1)

Steve Schmitt
Steve Schmitt

Reputation: 3209

There was a bug in the Breeze code that builds metadata from NHibernate models. As you discovered, it wasn't finding the foreign keys correctly when composite keys were used.

The fix for the issue is now on github and will be in the next release. Sorry it took so long!

Upvotes: 1

Related Questions