开发者

Mapping an entity to 2 tables

开发者 https://www.devze.com 2023-04-06 08:01 出处:网络
I have a position class that i want to be able to write to the database开发者_如何转开发.I currently have a entity for the class that is mapped to the database.I want to because to have the class inse

I have a position class that i want to be able to write to the database开发者_如何转开发. I currently have a entity for the class that is mapped to the database. I want to because to have the class insert data into one table and update entries in the other table. One table is for current positions and the other is for historical positions. Is it possible to map an entity to 2 tables and have it update 1 table and insert into the other?


Wouldn't it be easier to have a Trigger on the Update that Insert automatically a copy of the data in your history table?


Just don't do this. Use a database insert trigger.


I would make 2 different entities for this. If you want this to map to a single entity in your application you should write a data access class that (based on the data of your single entity) determines whether to do an update or an insert.

And I would personally never ever use a trigger for such a thing as this is business logic to me that needs to be exposed in the application so it can be tested.

0

精彩评论

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

关注公众号