开发者

Fluent NHibernate - mapping portions of a single table into multiple classes with a few shared fields

开发者 https://www.devze.com 2023-02-11 16:14 出处:网络
I have a situation where a User table has lots of information about a user (first name, last name, email, etc) in addition to credential data 开发者_C百科(username, password, prior passwords, etc).Nor

I have a situation where a User table has lots of information about a user (first name, last name, email, etc) in addition to credential data 开发者_C百科(username, password, prior passwords, etc). Normally I would separate Authentication from Personalization, but this table is long established and I can't do that.

It bothers me to have 1 user object with all this data in it that is being passed around my application. I instead want to split this out into two objects: User and UserCredentials. User can be freely passed around my application without leaking any of the passwords, while UserCredentials will be used only in my services backend for validating and authenticate a user.

That seems simple enough. However, some fields need to be shared across both these objects. Will this cause issues with nhibernate when one of my objects is updated? For instance if a username change takes place and both have the username in the object, will both objects be updated?


If User and UserCredentials represent two views of the same entity, do not create two classes for them. It'll only lead to pain.

Alternatives:

  • Use a component to expose the "public" part of the entity and pass that
  • Use a DTO to contain exactly the fields you need and pass that
0

精彩评论

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

关注公众号