使用实体框架与历史数据历史数据、实体、框架

2023-09-04 01:13:25 作者:不配拥有爱情

我建立在.NET 4.0中一个Windows应用程序来创建和组织电子项目。该应用的主要目的是记录的供应商信息,为电子元器件(部件编号,描述,价格等)和组织(准)成项目(成品)。其中一项要求是跟踪任何给定的供应商的项目(主要是价格)的变化而变化,在项目层面,为变化点的时间统计,在这两个组件级别和项目级别的细节。

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 electronics components (part #, description, price, etc.) and organize (associate) them into projects (finished products). One of the requirements is to track changes for any given vendor item (mainly price) and changes at the project level to provide a point-in-time statistics at both component level and project level details for changes.

我决定使用实体框架4我与SQL CE 3.5数据库的数据访问层,由于客户端部署的简单性。数据访问的伟大工程,但在尝试创建对象之间的关系(关联)时,框架不会出现任何明显的方法使用历史数据。这是我在使用实体框架的第一次尝试,所以我想这可能只是我的经验不足,那就是维持我从寻找答案。这是我的基本架构:

I decided to use Entity Framework 4 for my data access layer with SQL CE 3.5 for the database, given the simplicity of client deployment. The data access works great, but when attempting to create the relationships (associations) between objects, the framework doesn't appear to have any obvious way to use historical data. This is my first attempt at using the entity framework, so I figured it might just be my inexperience that's keeping me from finding the answer. Here's my basic schema:

我有3个主要的表:项目,产品和ProjectProduct

I have 3 main tables: Project, Product, and ProjectProduct

每个项目和产品表有一个ID列,这是用来为一体的复合键DateAdded列。该ProjectProducts表具有的ID对于每个其他两个表的,并保持所述实体之间的多对多的关系。关系表中也有一个DateAdded列跟踪变化的产品/项目的关联。

The Project and Product tables each have an ID column and a DateAdded column which are used as the complex key. The ProjectProducts table has the IDs for each of the other two tables and maintains the many-to-many relationships between the entities. The relationship table also has a DateAdded column to track changes in the product / project associations.

虽然实体框架似乎与维护协会是使用标准的code-生成的数据对象直接(无日期的标准)工作的伟大,它是如何得到它加载的关联将一个点有点混乱-in时间的历史数据模式。基本上我需要能够根据日期为标准点在时间要求(参数化加载)来加载的数据对象。

While the Entity Framework seems to work great with maintaining associations that are direct (no date criteria) using the standard code-generated data objects, it's a bit confusing on how to get it to load the associations for a point-in-time historical data schema. Essentially I need to be able to load the data objects based on the date criteria for the point-in-time requirements (parametrized loading).

有没有人做过类似的事情,可以在正确的方向指向我?

Has anyone done anything similar and can point me in the right direction?

抱歉长的解释,但在此先感谢您的帮助,您可以提供!

Sorry for the long explanation, but thanks in advance for any help you can provide!

推荐答案

我实现了同样的事情。这是pretty的易于使用EF4。你基本上处理OnSavingChanges事件,并列举了一系列改变的项目,将它们存储请你。

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.

本文将告诉您如何做到这一点,但我的实现是简单了很多(我不喜欢存储变化的XML,所以我做了列一个单独的表)

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)

实施审计跟踪利用实体框架 - 第1部分

第2部分显示了如何执行回滚,如果你有兴趣的。

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

实施审计跟踪利用实体框架 - 第2部分