0

I recently began using Fluent Nhibernate for my data layer and have come across an issue. Whenever i want to delete a record that has multiple foreign key constraints, i have to create another class just to represent that database entity. That means that for something like a User record, which has relationships with many other tables, i have to create something like 10 different classes that i will never use for any other purpose. At least that is my understanding of how things work.

Is there a way for me to delete all of these records without having to map them. For instance, using the User example, a User can have multiple roles, departments, email addresses, phone numbers, addresses, and so on. I would like to delete all of these records, but not have to map all of them in Nhibernate classes.

Is there a property i can set on my UserMapping that would accomplish this?

Thanks!

4

1 回答 1

1

如果这些实体没有被映射,NHibernate 就不可能知道它们。但是您可以选择以下替代方案之一:

  • 在数据库级别设置FK 级联(如果您的数据库支持)
  • 使用数据库触发器手动编码级联(如果您的数据库支持触发器)
  • 使用 IPostDeleteEventListener(类似于数据库触发器,但在 NHibernate 级别)手动编码级联。
于 2010-09-17T18:47:53.560 回答