Great! Glad I could help! ;-)

RP

On Monday, October 6, 2014 2:02:57 PM UTC+1, Charles Jenkins wrote:
>
>  Ricardo, 
>
> Thank you very much. To be clear for anyone who searches the archives for 
> information about similar difficulties, my entire problem was the default 
> value of “NULL” instead of “0” for a database-generated integer field.
>
> The field in question is my RowVersion property, mapped to a database 
> field named RowVer which is auto-generated by the database (actually, set 
> by a trigger). I didn’t think its default value mattered after telling NH 
> it was generated by the database, but obviously the lesson I’ve learned is 
> that all non-nullable values have to be legal, even if they’re not correct, 
> before save operations will work properly.
>
> To answer your question about Timestamp, its value starts out as whatever 
> crazy date the default for DateTime is, but it’s discarded upon write. Just 
> like with RowVersion, I’m using a MySQL trigger to set it when the row gets 
> created or updated. Once I took what you taught me and changed my helper 
> methods to these:
>
>     static public void MapRowVersion<T>( ClassMap<T> mapping ) where T : 
> IRowVersionedObject {
>
>       mapping.Version( x => x.RowVersion )
>
>         .Column( "RowVer" )
>
>         .UnsavedValue( "0" )
>
>         .Generated.Always();
>
>     }
>
>
>     static public void MapTimestamp<T>( ClassMap<T> mapping ) where T : 
> ITimestampedObject {
>
>       mapping.Map( x => x.Timestamp )
>
>         .Column( "TmStamp" )
>
>         .CustomSqlType( "DATETIME" )
>
>         .Generated.Always();
>
>     }
>
> I was successfully and repeatably able to create a more complex object 
> graph and persist it with a single Save():
>
>       using ( var sess = RemoteSessionHelper.OpenSession() ) {
>
>         using ( var tran = sess.BeginTransaction() ) {
>
>
>           var evil = new Tag() { Text = "evil" };
>
>
>           var company = new Company() {
>
>             OfficialName = "Rossum Corporation",
>
>             Nickname = "Rossum",
>
>             City = "Cerritos",
>
>             State = "CA",
>
>             Country = "US"
>
>           };
>
>
>           company.Tags.Add( evil );
>
>           company.Tags.Add( new Tag() { Text = "scientific" } );
>
>           company.Tags.Add( new Tag() { Text = "conglomerate" } );
>
>
>           var contact = new Contact() {
>
>             Name = "Adelle DeWitt",
>
>             Address1 = "[On File]",
>
>             City = "Los Angeles",
>
>             State = "CA",
>
>             Country = "US",
>
>             PostCode = "[On File]"
>
>           };
>
>
>           contact.Tags.Add( evil );
>
>           contact.Tags.Add( new Tag() { Text = "miss-lonely-heart" } );
>
>
>           company.AddContact( contact );
>
>
>           sess.Save( company );
>
>           tran.Commit();
>
>         }
>
>       }
>
>
> Wonderful! Thanks again :-)
>
> -- 
>
> Charles
>
> On Saturday, October 4, 2014 at 2:16, Ricardo Peres wrote:
>
> Hi,
>
> I replied to you privately with a slightly modified working sample.
> Some notes:
>
> - You didn't include code for the Tag and TagMap classes; shame on you! ;-)
> - The Timestamp properties were not being set; are you going to use some 
> listener for that? If so, you didn't mention it;
> - The Version was using an UnsavedValue of "NULL", which doesn't really 
> make sense - the field and the underlying column are both mapped as int, 
> which is never null - so I removed it and used DefaultValue;
>
> Everything works as expected, in my machine, at least!
>
> RP
>
> On Wednesday, October 1, 2014 11:22:26 PM UTC+1, Ricardo Peres wrote:
>
> Hi, Charles!
>
> I apologize, I didn’t see your mappings because Google Groups was hiding 
> part of the message - I had to click a "show trimmed message" link that I 
> hadn't noticed.
>
> Don't see anything obvious. Perhaps some other community member who is 
> more skilled than I have can help. I'll have a look anyway and will let you 
> know.
>
> RP
>
>
>
>
> On Wednesday, October 1, 2014 4:37:22 PM UTC+1, Charles Jenkins wrote:
>
> Ricardo,
>
> (I'm retrying a post that never appeared yesterday.)
>
> I don't understand remark 1 yet. As you can see in the CompanyMap object, 
> Cascade All is configured in the Company -> Contact mapping. Where else did 
> you mean I should put it?
>
> On Monday, September 29, 2014 4:39:11 PM UTC-4, Ricardo Peres wrote:
>
> Hi,
>
> Some remarks:
> 1) you don't need two Save calls if you configure cascading from one 
> entity's property to the other entity (company to contact); try "all";
> 2) the way you are deleting objects is vary bad, in performance terms; 
> see, for example, 
> http://weblogs.asp.net/ricardoperes/deleting-entities-in-nhibernate;
> 3) if you don't need GuidComb (and I guess not) you can use other Guid 
> flavors for a slight performance improvement - GuidComb ids are ordered 
> temporally.
>
> RP
>
>  -- 
> You received this message because you are subscribed to a topic in the 
> Google Groups "nhusers" group.
> To unsubscribe from this topic, visit 
> https://groups.google.com/d/topic/nhusers/H1693w-OFE0/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to 
> [email protected] <javascript:>.
> To post to this group, send email to [email protected] <javascript:>
> .
> Visit this group at http://groups.google.com/group/nhusers.
> For more options, visit https://groups.google.com/d/optout.
>  
>  
> 

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.

Reply via email to