-
Notifications
You must be signed in to change notification settings - Fork 934
NH-3667 & NH-3102 Dictionary mapping-by-code improvements #311
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
Conversation
«Stop, little pot» |
Needs something else... Like this! |
Fixed |
Hooray! |
@@ -1280,7 +1280,8 @@ protected virtual ICollectionElementRelationMapper DetermineCollectionElementRel | |||
{ | |||
return new OneToManyRelationMapper(propertyPath, ownerType, collectionElementType, modelInspector, customizerHolder, this); | |||
} | |||
if (modelInspector.IsManyToMany(property)) | |||
//NH-3667 & NH-3102 | |||
if ((modelInspector.IsManyToMany(property)) && ((property.GetPropertyOrFieldType().GetGenericArguments().Length < 2) || ((property.GetPropertyOrFieldType().GetGenericArguments().Length > 1) && (modelInspector.IsEntity(property.GetPropertyOrFieldType().GetGenericArguments()[1]))))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For readability, can we get that split on several lines please? Use a nested if-statement if it helps readability.
Alex, you are a hard man to please! :-) |
{ | ||
var args = property.GetPropertyOrFieldType().GetGenericArguments(); | ||
|
||
if ((args.Length < 2) || (args.Length > 1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably I'm stupid, but I don't understand that condition:(
You're not stupid! :-) |
I'm asking only about args.Length < 2 || args.Length > 1 |
If we have a generic collection with a single generic parameter (eg, IList) or if we have one with two (eg, IDictionary<TKey, TValue>)... |
(args.Length < 2 || args.Length > 1) is true always 0 - true ( args.Length < 2 is true) |
Alexei: |
I cleaned up the code. Can you try rebuilding? |
I cannot tell - is the change made in the correct place or is it the implementation of modelInspector.IsManyToMany() that should really change? There is such a large number of classes there, with very little documentation, so I must admit I'm confused. |
The two errors from ExplicitColumnNameIsAlwaysMapped are caused because class Bar is not mapped. The test would also fail if we were to open a session factory - see for yourself. |
The problem is that whenever we call IMapKeyRelation.ManyToMany to register an entity key the property is registered as a many to many in class AbstractExplicitlyDeclaredModel. So method ModelMapper.DetermineCollectionElementRelationType assumes that the collection value is an entity, but sometimes it is an element or a component. My solution fixes this, but there are other possibilities. I think this is an important issue. |
Hi Ricardo, could you please squash all this stuff? Or alternatively - could you add me to your fork? |
Alex: what do you mean? |
What question is confusing you? |
Well, the "add me to your fork" is easy, but what do you mean by "squash all this stuff"? |
Right, I added you, because I'm on an ipad far away from my machine. Will only be back by sunday. |
Ok, thanks |
So this is ready to go in then? To be honest it looks a bit like a hack to me, but the test case seems solid and the code is localized so I don't think it's too much of a problem. The related DetermineMapKeyRelationType() does contain the comment "Perhaps we have to change IModelInspector with IsDictionaryKeyManyToMany(member), IsDictionaryKeyComponent(member) and so on", which might be a hint that really MapKeyManyToManyCustomizer should do something slightly different than just I havent't studied the code close enough to tell really... so this patch LGTM. |
NH-3667 & NH-3102 Dictionary mapping-by-code improvements
https://nhibernate.jira.com/browse/NH-3667
https://nhibernate.jira.com/browse/NH-3102