开发者

Is there anything in nhibernate that lets me get the list of mapped classes that refer some other class?

开发者 https://www.devze.com 2023-02-10 13:55 出处:网络
Is there some feature in n开发者_StackOverflow社区hibernate that goes through all the mapping files and can get me a list of class names that refer to (many to one) another class?

Is there some feature in n开发者_StackOverflow社区hibernate that goes through all the mapping files and can get me a list of class names that refer to (many to one) another class?

It would be quite handy, if I could do this, then I could run some queries to tell the user exactly why they're not allowed to delete certain values, instead of throwing a gross looking foreign key violation message...

Thanks

Isaac


An extremely simplified approach:

foreach (var classMetadata in sessionFactory.GetAllClassMetadata())
    foreach (propertyType in classMetadata.PropertyTypes)
        if (propertyType.IsEntityType)
            //this is a foreign key

Then you have sessionFactory.GetAllCollectionMetadata(), etc.

This should get you started.

0

精彩评论

暂无评论...
验证码 换一张
取 消