Page 1 of 1

Change collection-type in .hbm-files?

Posted: Thu 12 Jun 2014 12:27
by Obi Bieber
Dear Sir or Madam,

in our current project we make great use of Entity Developer in combination with .net and wpf. The problem was: How to make Iesi.Collection.ISet notifyable as for example ObservableCollection<T>. We have solved this issue using our own classes like PersistentObservableSet, ObservableHashedSetType and ObservableSet. Also we have modified the default template file (.tmpl) of Entity Developer to modify the Type of the collections in the .cs-Domain-files. In our mapping files (hbm.xml) however we defined the collection sets MANUALLY (after generating c#-code from within Entity Developer) as following: <set name="MietartikelTarifes" inverse="true" generic="true" collection-type="Obi.Persistance.Common.ObservableHashedSetType`1[[MietartikelTarife]], Obi.Persistance">. And it made our day. Perfect. But as we own Entity Developer licence it would the best to generate the collections in mapping of our Entities of type "Obi.Persistance.Common.ObservableHashedSetType`1[[MietartikelTarife]]" BY THE TOOL. How can we achieve this? Is there a solution out there? Have we overseen any buttons / checkboxes? Is there anything we can do more with template files?

Best regards

Vadim

Re: Change collection-type in .hbm-files?

Posted: Tue 17 Jun 2014 16:17
by Shalex
Thank you for your suggestion. We will notify you when the possibility of specifying custom collection type name for HibernateRelationProperty via interface of Entity Developer is implemented.

Re: Change collection-type in .hbm-files?

Posted: Tue 08 Jul 2014 14:17
by Obi Bieber
Dear Sir or Madam,

do you have plans for releasing this feature in the near future? If you do, could you say when it will be released? We really need this feature. We are about to help us only by modifying code manually and this is really annoying and time intense.

Best regards

Vadim

Re: Change collection-type in .hbm-files?

Posted: Thu 10 Jul 2014 11:05
by Shalex
We will try to implement the feature before releasing the next public build (in two weeks).

Re: Change collection-type in .hbm-files?

Posted: Tue 15 Jul 2014 13:18
by Obi Bieber
Sounds good! Thank you!

Kind regards,
Vadim

Re: Change collection-type in .hbm-files?

Posted: Thu 31 Jul 2014 16:23
by Shalex
The new (5.7.412) build of Entity Developer is available for download. This version allows to implement the needed functionality in the following alternative ways:

1. Via interface of Entity Developer.
Navigate to Model Settings > Model > Extended Properties > RelationProperty > press Add and set Name=CollectionTypeName, Property Type=System.String > OK.
Now select HibernateRelationProperty, and you will find Collection Type Name in the Extended Properties submenu in the Properties window. Specify the type name. As a result, collection-type="specified_type_name" will be added in the corresponding <set/> section in *.hbm.xml.

2. By modifying template via embedded T4 Editor. Add the following entry in the template:

Code: Select all

<#@ extended name="CollectionTypeName" owner="RelationProperty" type="System.String" description="The assembly-qualified name of the custom collection type." #>
Now select HibernateRelationProperty, and you will find Collection Type Name in the Extended Properties submenu in the Properties window. Specify the type name. As a result, collection-type="specified_type_name" will be added in the corresponding <set/> section in *.hbm.xml.

Re: Change collection-type in .hbm-files?

Posted: Mon 11 Aug 2014 13:17
by Obi Bieber
Thank you very much! This works very well for us! :D

Kind regards,
Vadim

Re: Change collection-type in .hbm-files?

Posted: Thu 25 Apr 2019 20:00
by ispcdev
We use a custom collection for all our bag relationships. Is there a way to specify the custom collection is generic using the Default Value of the CollectionTypeName property? I see how to do it for each individual field, but we have a large number tables, so it would be convenient if this could be automated.

Thanks.

Re: Change collection-type in .hbm-files?

Posted: Fri 03 May 2019 09:19
by Shalex
We will investigate the question and notify you about the result.

Re: Change collection-type in .hbm-files?

Posted: Tue 07 May 2019 12:56
by ispcdev
We ended up modifying the GetRelationPropertyCollectionInitialization method in the NHibernate template as shown below. This accomplished our goal, but am concerned about long term effects of customization to the templates when there are product updates.

Code: Select all

case HibernateCollectionType.Idbag:
        //Customized this to use the our custom collection
        if (relationProperty.Generic)
          return string.Format("Data.Lists.ObservableList<{0}>()", relationClassName);
        else
          return "ArrayList()";
Side Note: Entity Developer has saved us a lot of time on our project. Thanks.

Re: Change collection-type in .hbm-files?

Posted: Fri 07 Jun 2019 17:46
by Shalex
The bug with applying Generic=True to the CollectionTypeName extended relation property (it is predefined now) in the NHibernate template is fixed: viewtopic.php?f=32&t=38876.