将审核列添加到 Fluent NHibernate 多对多联结表
我正在使用 Fluent NHibernate 从 .Net 实体类生成数据库架构。我有两个具有多对多关系的类 User
和 Permission
,Fluent NHibernate 在数据库中正确生成了一个联结表 UsersToPermissions
。
正如预期的那样,联结表存储主键 UserId
和 PermissionId
。我想要的是将审核信息附加到该表,例如 CreatedDate 和 UpdatedDate。我已经使用拦截器在非联结表上实现了此功能,如 NHibernate 文档< /a>.
如何在 UsersToPermissions
表上实现审核列?
I'm using Fluent NHibernate to generate a database schema from .Net entity classes. I have two classes User
and Permission
with a many to many relationship, and Fluent NHibernate is correctly generating a junction table UsersToPermissions
in the database.
As expected the junction table is storing the primary keys UserId
and PermissionId
. What I am wanting is to also have auditing information attached to this table such as CreatedDate
and UpdatedDate
. I have already implemented this on the non junction tables using interceptors as described in the NHibernate documentation.
How can I implement audit columns on the UsersToPermissions
table?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
直接不可能,因为关系没有属性。
最简单的方法是将联结表映射为实体,并使用 LINQ-to-objects 投影边以方便使用。
例如,假设我们将中间实体称为
UserPermission
:如果需要,Permission 可以具有完全相同的权限。
It's not possible directly, because relationships don't have properties.
The easiest way is to map the junction table as an entity, and project the sides using LINQ-to-objects for ease of use.
For example, assuming we call the intermediate entity
UserPermission
:Permission can have exactly the same if needed.