-
Notifications
You must be signed in to change notification settings - Fork 687
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HasMany().Not.KeyNullable() uni-directional mapping generates NULLable FK DDL #414
Comments
I have exactly the same need, and exactly the same problem. It is not a problem to alter the database script by hand, since we do not rely on automatic schema updates, and instead roll out hand-written migration scripts. However, it would be nice to see that HNIbernate respects the mapping configuration, and generates proper schema. Otherwise, how can we be sure that it won't try to do insert null and then subsequent update to a value during session flush at runtime? |
What's the state of this? |
@rgomez90 as far as I know, no one work on this. You are more than welcome to submit a PR. See contributing. |
@hazzik thank you. |
Did u attempt to fix this bug yet or did you blocked? |
Hey, looking at the generated mapping xml fluent nhibernate generated i see this
In the documentation here ( https://nhibernate.info/doc/nhibernate-reference/collections.html#collections-example) it show what the xml mapping should look like if you want the FK to be not nullable
Notice the different in the column attribute vs the column node. Are the both the same and valid mappings? |
yes |
Also seeing this. It seems at least the schema generator is not picking up the not-null value from the parent key element when the column is a child, not an attribute. |
In NHibernate, the column name as a child element versus as an attribute produces different while the HbmXxx XML schema classes are interpreted into the CollectionBinder.BindKey() will get the HbmKey object, then call ValuePropertyBinder.BindSimpleValue(). The third parameter of that method is called Inside of that, it will iterate the columns (as None of the above directly looks at the So, in summary, the following two alternatives are not treated exactly the same by NHibernate: <set name="Children">
<key column="parent_id" not-null="true"/>
<one-to-many class="Child"/>
</set> <set name="Children">
<key not-null="true">
<column name="parent_id"/>
</key>
<one-to-many class="Child"/>
</set> |
There is a workaround: HasMany(sg => sg.Items).AsSet()
.Not.KeyNullable()
.KeyColumns.Add("parent_id", part => part.Not.Nullable()) That works, as opposed to using the |
Hello,
It seems like
HasMany().Not.KeyNullable()
not quite properly generates DDL with SchemaExport. Assuming it should output NOT NULL FK column on the child side. However what I get is NULLable FK column.The background of such modelling is the DDD related motivations where the AggregateRoot is managing its child entities, but children are not holding back reference to the AggregateRoot.
Am I doing something wrong or is this not working as I expect it to?
Cheers
The text was updated successfully, but these errors were encountered: