Using Entity Framework with historical data

后端 未结 1 1905
情话喂你
情话喂你 2021-02-13 20:05

I\'m building a windows application in .Net 4.0 to create and organize electronics projects. The main purpose of the application is to record the vendor information for the ele

1条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-13 21:02

    I implemented the exact same thing. It's pretty easy with EF4. You basically handle the OnSavingChanges event, and enumerate the set of changed items, storing them as you please.

    The only problem is, it is VERY tricky to get inserted items (unless you are ok with not having a Primary Key of the new item, which I was not) I decided to only track updates and deletes.

    This article shows you how to do it, though my implementation was a lot simpler (I didn't like storing changes in XML so I made a separate table for columns)

    Implementing Audit Trail using Entity Framework - Part 1

    part 2 shows how to do rollbacks, if you are interested in that.

    Implementing Audit Trail using Entity Framework - Part 2

    0 讨论(0)
提交回复
热议问题