复合主键 - 审核更改? [英] Compound Primary Keys - auditing changes?
问题描述
考虑一个员工薪资历史实体,带有复合主键 - EmployeeID,EffectiveDate,EffectiveSequence。
我需要审核任何更改如果进行了更改,则为EffectiveDate和/或EffectiveSequence - 例如3月1日输入的加薪,但后来更正为4月1日。
是否有一种简单的方法可以覆盖SaveChanges()来检测更改键。
当然我可以遍历OriginalValues和CurrentValues以查看是否有更改 - 但只是想知道是否还有其他方法。
谢谢
John
Hi,
Consider an Employee Salary History entity, with a Compound Primary Key -- EmployeeID, EffectiveDate, EffectiveSequence.
I need to audit any changes to EffectiveDate and/or EffectiveSequence if a change were made - such as a pay rise entered for March 1st, but later corrected to April 1st.
Is there an easy way wthin Override SaveChanges() to detect a change in the Keys.
Of course I can iterate over the OriginalValues and CurrentValues to see if there are changes - but just wondered if there was any other way.
Thanks
John
推荐答案
嗨约翰,
EF实际上不支持更改键值,如果要更改键值,则需要直接与数据库交互。您可以通过DbContext.Database.ExecuteSqlCommand或ObjectContext.ExecuteStoreCommand执行此操作。
EF actually doesn't support changing key values, if you want to change key values you will need to interact directly with the database. You can do this via DbContext.Database.ExecuteSqlCommand or ObjectContext.ExecuteStoreCommand.
~Rowan
这篇关于复合主键 - 审核更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!