c# - Nhibernate and the case of Auto Updating Entities -



c# - Nhibernate and the case of Auto Updating Entities -

best title come with, little more involved however.

// nail database 1 time , categories; iqueryable<category> qrycategorylist = _repository.select<category>(); // initial parents var parentcategories = qrycategorylist.where(x => x.parentcategoryid == null); foreach (category parentcategory in parentcategories) { httpcontext.current.response.write(parentcategory.categoryname = "this should not happen"); buildcategorylist(qrycategorylist, parentcategory.categoryid); }

this line

httpcontext.current.response.write(parentcategory.categoryname = "this should not happen");

performs this

update categories set parentcategoryid = null /* @p0_0 */, categoryname = '->' /* @p1_0 */, categorydescription = 'the fruit category' /* @p2_0 */, active = 1 /* @p3_0 */, datecreated = '2012-01-20t12:03:41.00' /* @p4_0 */, lastupdated = '2012-01-20t12:03:41.00' /* @p5_0 */ categoryid = 'aa8ca9ba-663c-45c8-950b-159a28e6635d' /* @p6_0 */

i not calling save repository not wanting update. how possible?

edit: here mapping

public class categorymap : classmap<category> { public categorymap() { table("categories"); lazyload(); id(x => x.categoryid).generatedby.guidcomb().column("categoryid"); map(x => x.parentcategoryid).column("parentcategoryid"); map(x => x.categoryname).column("categoryname").not.nullable().length(50); map(x => x.categorydescription).column("categorydescription").not.nullable(); map(x => x.active).column("active").not.nullable(); map(x => x.datecreated).column("datecreated").not.nullable(); map(x => x.lastupdated).column("lastupdated").not.nullable(); hasmany(x => x.postingscategories).keycolumn("categoryid"); } }

this happens when in mapping or object declaration doesn't quite jive what's in database. example, might have uniqueidentifier in database that's nullable mapped non-nullable guid on object. nhibernate selects, sees guid.empty instead of null, , says "hey! object changed! whelp, reckon should update it..."

that's 1 case of how can happen. if post mapping, might able help debug bit further.

--

actually, should have read bit further. if within scope of transaction, nhibernate auto update changed entities without needing explicit phone call saveorupdate(). it's called autoflush , it's on default. you'll need set flushmode never if want explicitly phone call transaction.commit() or session.flush().

c# nhibernate

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -