c# - In the nhibernate, how can I determine if a mapped entity has cascade = "all"? -
i'm making general nhibernate method can determine, given instantiated nhibernate mapped object @ runtime, if object referenced other object in 'database'.
this way, i'll able allow user delete objects if not referenced, , throw errors if (along info how many things reference object).
i ran snag though, when entity mapped cascade = all, want them able delete thing though other objects reference it.
so, need know how can use nhibernate.metadata.iclassmetadata determine if 'entity type' or bag cascade = all. can't seem find after looking few minutes.
any thoughts?
thanks
isaac
p.s. here method code (unfinished). idomainobject makes sure passed object has int id property.
public int getreferencecount<t>(t objecttocheck) t : interfaces.idomainobject { type objecttype = typeof(t); string classname = objecttype.name; idictionary<string, nhibernate.metadata.iclassmetadata> mydictionary = session.sessionfactory.getallclassmetadata(); int referencecount = 0; string fullclassname = objecttype.fullname; foreach (var thisclasspair in mydictionary) { nhibernate.metadata.iclassmetadata thisclass = thisclasspair.value; (int = 0; < thisclass.propertytypes.length; i++) { string propertyname; if (thisclass.propertytypes[i].name == fullclassname) { if (thisclass.propertytypes[i] nhibernate.type.manytoonetype || thisclass.propertytypes[i] nhibernate.type.onetoonetype) { propertyname = thisclass.propertynames[i]; list<object> results = this.hqlquery<object>("from " + thisclasspair.key + " refclass refclass."+propertyname+".id = '"+objecttocheck.id+"'"); } } } } return 0; }
var persister = (nhibernate.persister.entity.abstractentitypersister)thisclass; var cascadestyle = persister.getcascadestyle(i);
Comments
Post a Comment