Why NHibernate updates old entities in DB though no id is assigned -


i'm using fluent nhibernate , ms sql express 2012.

when want save entities db create them , call isession.save() or isession.saveorupdate() not setting id fields. works fine until stop application , start again. after new entities not added db. instead when call save() or saveorupdate() updates old ones.

why nhibernate behaves this? seems me when don't set id field must add new entity db not update old one.

here's example:

consider have class foo:

public class foo {     public virtual long id { get; set; }     public virtual string value { get; set; } } 

and mapping:

public class foomap : classmap<foo> {     public foomap()     {         id(foo => foo.id)             .generatedby.native();          map(foo => foo.value);     } } 

here's how save them db:

var foo1 = new foo { value = "aaa" }; var foo2 = new foo { value = "bbb" };  var sf = config.buildsessionfactory(); using (var sess = sf.opensession()) {     using (var tr = sess.begintransaction())     {         sess.save(foo1);         sess.save(foo2);          tr.commit();     } } 

after there 2 entities in db. stop appliction, change values of value-field, , start on again (i.e. crate new sessionfactory). after above code no new entities added db. instead old ones have value-field values.

p.s.: couldn't find db driver ms sql server 2012, had use driver ms sql 2008. problem?

there's schemaupdate creates tables/columns don't exist yet


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -