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

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -