Hi,
I (and others) have been struggling with mapping a dictionary with entity keys using FNH. Only when using HasManyToMany are ternary associations supported at the moment. But I guess most people would more often use HasMany to define an entity-map (i.e. dictionary with entity keys) when having a collection of children. I need this mapping, and would like to see it in the official master branch.
I have relatively little experience with the FNH codebase but have managed to come up with the update for supporting HasMany-entity-maps. The update can be seen from the entity-map branch of my fork that has one commit.
I have also fixed a bug that happens when having an indexed collection (map) inside a component. See the commit for more info
Kind regards
Maxild
Thanks.
One thing to look at is that my API on OneToManyPart is a bit smaller than the corresponding API on ManyToMamyPart. Also I have introduced a member called IsEntityMap(). I guess the API’s should be more consistent.
Give me a sign if/when something have been committed to master, or let me know if you need help with anything.
/Morten
Hi Paul,
Yes this was the inconsistency, I was referring to. Off course a OneToMany only has an overload with a single ‘string indexColumnName’ parameter, to pass an arg (e.g. ‘MyNameFoTheKeyOrIndexColumn’) to get this xml
<index-many-to-many class="...">
<column name="MyNameFoTheKeyOrIndexColumn" />
</index-many-to-many>
Also the AsEntityMap method (that isn’t found on ManyToManyPart, another inconsistency) should have the same overloaded as well, or be dropped from the API. IMO it reads well.
Finally I believe that the (new) ‘string indexColumnName’ parameter on AsTernaryAssociation/AsEntityMap shouldn’t be confused with the parameter on the AsMap() method, as shown by this test the former controls the column-name on the index element (as opposed to the index-many-to-many element). This is a confusing, I guess.
[Test]
public void CanSpecifyCollectionTypeAsMapWithStringColumnName()
{
new MappingTester<OneToManyTarget>()
.ForMapping(map => map
.HasMany(x => x.MapOfChildren)
.AsMap("Name")
.KeyColumns.Add("ParentId"))
.Element("class/map/key/column").HasAttribute("name", "ParentId")
.Element("class/map/index/column").HasAttribute("name", "Name")
.Element("class/map/one-to-many").HasAttribute("class", typeof(ChildObject).AssemblyQualifiedName);
I’ll take a look tonight, and provide you some feedback:-Morten
Hi
First, Do you now when James will pull, or do you have access to push to the ’official’ master?
Then, my feedback….first all tests passJ
Your new specs do not verify the rendered xml through xpath queries, but test the internal semantic model (didn’t know about ModelShouldMatch to verify internal semantic model). And you left my tests that specify the expected rendered xml. I guess you can have too many tests, but in this case I like both, and leaving mine is nice documentation trying to learn FNH with a NH background (easier to read tests specifying the hbm/xml output according to the NH XSD grammar)?
I guess you could delete the ManyToManySubPartModelGenerationTests.cs, as it is empty.
Also the fix to the XmlClasslikeNodeSorter is kind of hidden in the commit (no issue, my mistake), but I hope you guys can live with that (some of the tests, EntityMapOfComplexValuesXXXX, are failing tests without the fix, because they verify the correct position of the child elements ‘key’, ‘index-many-to-many’ and ‘composite-element’)
Nice work, looking forward to delete my entity-map-branch