开发者

NHibernate delete entity - check for references

Is there a generic solution to check for references when the user will delete an entity and it could not be deleted because there are references to it? I search a solution which works in all situation. The user try to delete, I can check in my DataAccess-Layer and 开发者_StackOverflow社区give the user a message "Entity could not be deleted because there are references". How do you solve this problem?


It you don't need to know what references are, you can catch the FK exception in you DAL, and wrap it to your Service layer into a ReferencedObjectsException, with appropriate error message.

Otherwise, you would have to look at the mappings (by code), determine the references (by code), and check for dependencies (by code).

Rhino.Security has a Mapping rewriting part here : https://github.com/ayende/rhino-security/blob/master/Rhino.Security/Impl/MappingRewriting/UserMapper.cs, from the NHibernate configuration object, you have access to the Class Mappings.


You need to map the related entities and include the cascade='all-delete-orphan' option.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜