开发者

NHibernate Mapping Question - Bizarre scenario

I have an interesting scenario where I have a given table that maps to an entity. However, there is another version of the table which gets populated as part of a nightly process and has the exact same columns as the first table. Without getting into too many details, the second table is a "working" table with a small subset of records. There are some weird business rules where inserts can only be done into the large table and reads/updates can only be done on the smaller table.

How could I handle mapping this? In other words, in same cases I want a CRUD operation to use one mapping and in other scenarios I want to us开发者_高级运维e the other table.


You can do this by either maintaining two session factories with each mapping the same Entity to each table, or by using two diferewnt entities in a single session factory with each entity (class) mapped to it's own table.


I would handle this as two separate entities and map them separately to the same table. If you're using repositories you could then enforce the rule that the inserts are possible for one entity and selects/updates in the other.


You also may set different sql on load/write operations - in this case you have the complete control among process.


Create two entities and have each mapped to their own separate table. Since the tables are mirrors of each other only use one entity throughout the application. When it comes time to save the entity check an IsNew flag. If IsNew is true then simply save (insert). If IsNew is false then copy the values to the secondary entity and save (update) that. This way you don't have to worry about passing two different entities around in your application. It should keep the confusion down when reading through the code because you don't have to worry about what entity your using.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜