Mapping to insert instead of select + update on child collection

192 views
Skip to first unread message

Mikael Henriksson

unread,
Nov 11, 2009, 9:12:29 AM11/11/09
to Fluent NHibernate
Hi,

How would I fluently map so that I perform inserts instead of select and update.
What I want to accomplish is the following (I think this should turn of updates and just perform inserts?):


<many-to-one cascade="all" update="false" insert="true" class="Data" foreign-key="data_id" name="Data">
    <column name="data_id" />
</many-to-one>

How would I do this in FNH?

Paul Batum

unread,
Nov 19, 2009, 3:04:19 AM11/19/09
to fluent-n...@googlegroups.com
Hi Mikael,

You've probably already figured this out yourself... but does this do the trick?

References(x => x.Something)
   .Cascade.All
   .Not.Update()
   .Insert()
   .ForeignKey()

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Fluent NHibernate" group.
To post to this group, send email to fluent-n...@googlegroups.com
To unsubscribe from this group, send email to fluent-nhibern...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/fluent-nhibernate?hl=en
-~----------~----~----~----~------~----~------~--~---


Mikael Henriksson

unread,
Nov 19, 2009, 7:40:27 AM11/19/09
to fluent-n...@googlegroups.com
Thanks Paul, I did figure it out but it was not exactly what I was looking for I was actually wanting to do this on the other side so I ended up with Readonly() on the entity (means only inserts or mutable = false in nhibernate). And the other was to remove the Assigned for the entity key. I am actually working on some unit tests to prove my theories at the moment. Will come back with the solution to my question later.


--

You received this message because you are subscribed to the Google Groups "Fluent NHibernate" group.
To post to this group, send email to fluent-n...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/fluent-nhibernate?hl=.

Mikael Henriksson

unread,
Nov 19, 2009, 8:49:38 AM11/19/09
to fluent-n...@googlegroups.com
Ok the following works like a fucking charm (pardon the language) except that since I only do inserts it does not update the version automatically and I'd rather not leave that to whoever is writing the persistence service ;)
Any suggestions to how I can intercept and automatically increment the version where contact_id = ? and contact_version_id = ?. Do I need to use the event subsystem for that? 
(I posted this to NH Users since it's prolly easier to get the right type of help there: http://groups.google.com/group/nhusers/browse_thread/thread/6fdbf19609f6bfd4 )

public class ParentMap : ClassMap<Parent>
{
    public ParentMap()
    {
        Table("parent_def");      
        Id(x => x.Id,"parent_id");
        Map(x => x.UID, "parent_uid").CustomSqlType("varchar").Length(40);
        Map(x => x.DeletedAt ,"dte_deleted").Nullable();
        Map(x => x.ModifiedAt, "dte_modified").Nullable();
        Map(x => x.CreatedAt, "dte_created").Nullable();
        Map(x => x.AutoUpdate, "auto_update").CustomSqlType("bit");
       
        HasMany(x => x.ParentVersions)
            .KeyColumn("parent_id")
            .Inverse()
            .Cascade.All();
    }
}
 
public class ParentVersionMap : ClassMap<ParentVersion>
{
    public ParentVersionMap()
    {
        Table("parent_version");
        ReadOnly();
 
        Id(x => x.Id  ,"parent_version_id");
        Version(x => x.Version)
            .Column("parent_version")
            .Generated.Never();
        Map(x => x.ParentHash ,"parent_hash")
            .CustomSqlType("varchar")
            .Length(40);
        Map(x => x.DateCreated ,"dte_created");
        Map(x => x.UpdateAvailable, "update_available");
 
        References(x => x.Parent, "parent_id")
            .ForeignKey("parent_id");
    }
}
Reply all
Reply to author
Forward
0 new messages