codesmithtools / Templates

CodeSmith Generator Templates
http://www.codesmithtools.com/product/generator
54 stars 35 forks source link

No One-To-One support for nHibernate Framework? #175

Closed GoogleCodeExporter closed 4 years ago

GoogleCodeExporter commented 9 years ago
I have a few one to one relationships in a database I am generating code
for, and I realized that the CodeSmith templates have no support for one to
one mappings.  Is this by design?

Original issue reported on code.google.com by eric...@gmail.com on 17 Oct 2009 at 5:55

GoogleCodeExporter commented 9 years ago
When we created our NHibernate templates we did not include support for 
one-to-one
relationships; however, we do intend to add this in a future release.

NOTE: To accomplish this the templates would have to identify tables that are 
keyed
to each other, as well as check for a unique constraint of the foreign keys 
between
to the two rows. For an example, see PLINQO's IsOneToOne method (line 452 in
DbmlGenerator.cs).

Original comment by tdupont...@gmail.com on 21 Oct 2009 at 4:07

GoogleCodeExporter commented 9 years ago
Has there been any progress on this feature?

Original comment by juffend...@gmail.com on 3 Aug 2011 at 4:53

GoogleCodeExporter commented 9 years ago
Issue 600 has been merged into this issue.

Original comment by bniemyjski on 3 Aug 2011 at 7:51

GoogleCodeExporter commented 9 years ago
Hello,

I just came across this issue myself today... And I created case 600, which I 
ended up merging into this case. I'll make SURE this gets updated in the next 
minor release of PLINQO for nHibernate. I was very surprised to find that this 
wasn't in the initial 1.0 release of the PLINQO for nHibernate templates...

---- Merged info below ----

The templates should generate one to one mappings in the hbm and generated 
entities: http://ayende.com/blog/3960/nhibernate-mapping-one-to-one

There are currently two work-arounds to get around this limitation until these 
changes have been made. The first work around would deal with updating the HBM 
with the one-to-one information as we preserve custom changes to the HBM files 
on regeneration. The next step would be to place the association properties in 
the non-generated partial class (E.G., Entities\MyEntitiy.cs).

The second work around would be to update the HBM template 
(CSharp\Internal\Hbm.Entity.cst) and CSharp\Internal\Entity.Generated template 
with the respected one-to-one association code. Next, one would need to update 
and recompile the Source Project to load the new one-to-one associations. This 
would need to take place around line 121 of the 
PLINQO-NH/Source/CodeSmith.SchemaHelper.NHibernate/NHibernateEntity.cs class 
file.

Original comment by bniemyjski on 3 Aug 2011 at 7:54