c# - Showing related entities when delete -
i have model relations mapped nhibernate , working fine, sample:
public class { public int id { get; set; } // other properties public icollection<b> blist { get; set; } public icollection<c> clist { get; set; } public icollection<d> dlist { get; set; } }
the persistence , reading kind of entity works fine, when user delete a
entity, show him there 1 or more entities related (not entity (id, name etc..) type of entity), sample:
you cannot delete register because there relations with: -b -d
(if a
entity, has b
's or d
's relations , not c
's).
i know can information checking entity entity, have generic solution, there way?!
nhibernate has own metadata api, allows read mapping information, including collections mapped properties, , property types. type of each property, can find out name of related type.
a instance = ... var metadata = this.session.sessionfactory.getclassmetadata(instance.gettype()); foreach(itype propertytype in metadata.propertytypes) { if(propertytype.iscollectiontype) { var name = propertytype.name; var collectiontype = (nhibernate.type.collectiontype)propertytype; var collection = collectiontype.getelementscollection(instance); bool hasany = collection.count > 0; } }
Comments
Post a Comment