Change collection-type in .hbm-files?

Discussion of open issues, suggestions and bugs regarding Entity Developer - ORM modeling and code generation tool
Post Reply
Obi Bieber
Posts: 4
Joined: Thu 12 Jun 2014 12:12

Change collection-type in .hbm-files?

Post by Obi Bieber » Thu 12 Jun 2014 12:27

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

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

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

Post by Shalex » Tue 17 Jun 2014 16:17

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.

Obi Bieber
Posts: 4
Joined: Thu 12 Jun 2014 12:12

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

Post by Obi Bieber » Tue 08 Jul 2014 14:17

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

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

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

Post by Shalex » Thu 10 Jul 2014 11:05

We will try to implement the feature before releasing the next public build (in two weeks).

Obi Bieber
Posts: 4
Joined: Thu 12 Jun 2014 12:12

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

Post by Obi Bieber » Tue 15 Jul 2014 13:18

Sounds good! Thank you!

Kind regards,
Vadim

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

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

Post by Shalex » Thu 31 Jul 2014 16:23

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.

Obi Bieber
Posts: 4
Joined: Thu 12 Jun 2014 12:12

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

Post by Obi Bieber » Mon 11 Aug 2014 13:17

Thank you very much! This works very well for us! :D

Kind regards,
Vadim

ispcdev
Posts: 4
Joined: Thu 25 Apr 2019 19:50

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

Post by ispcdev » Thu 25 Apr 2019 20:00

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.

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

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

Post by Shalex » Fri 03 May 2019 09:19

We will investigate the question and notify you about the result.

ispcdev
Posts: 4
Joined: Thu 25 Apr 2019 19:50

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

Post by ispcdev » Tue 07 May 2019 12:56

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.

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

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

Post by Shalex » Fri 07 Jun 2019 17:46

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.

Post Reply