1

目前,我正坐在一个用 Access 编写的丑陋业务应用程序上,该应用程序每天两次获取电子表格并将其导入 MDB。我目前正在将一个包含此内容的主要项目转换为 SQL Server 和 .net,特别是在 c# 中。

为了容纳这些信息,有两个表(此处为别名),我将它们称为 Master_Prod 和 Master_Sheet,它们连接到 Master_Prod 表 ProdID 的身份密钥父级。还有另外两个表来存储历史记录,History_Prod 和 History_Sheet。Master_Prod 之外还有更多的表,但出于解释目的,将其限制为两个表。

由于这是用 Access 编写的,因此处理此文件的子例程充满了手动编码的触发器,以处理过去和一直难以跟上的历史,这是我很高兴将其转移到数据库服务器的一个原因而不是 RAD 工具。我正在编写触发器来处理历史跟踪。

我的计划是/是创建一个对电子表格进行建模的对象,将数据解析到其中并使用 LINQ 在将数据发送到服务器之前进行一些客户端检查......基本上我需要将工作表中的数据与匹配的数据进行比较记录(除非不存在,否则它是新的)。如果任何字段已更改,我想发送更新。

最初我希望将此过程放入某种接受 IEnumerable 列表的 CLR 程序集中,因为我已经有了这种形式的电子表格,但我最近了解到这将与一个相当重要的数据库服务器配对,我我非常担心陷入困境。

这值得放入 CLR 存储过程吗?还有其他数据进入的入口点,如果我可以构建一个过程来处理传入的对象,那么我可以从应用程序中删除很多业务规则,但会牺牲潜在的数据库性能。

基本上我想把更新检查从客户端拿走,然后把它放在数据库上,这样数据系统就可以管理表是否应该更新,这样历史触发器就可以触发了。

是否有沿同一方向实施的更好方法的想法?

4

3 回答 3

3

使用SSIS。使用Excel Source读取电子表格,也许使用查找转换来检测新项目,最后使用SQL Server 目标将丢失的项目流插入 SQL。

无论 linq 多么有趣,SSIS 都更适合从头开始编写东西的这类工作。SSIS 包比一些带有被遗忘源的 dll 更容易调试、维护和重构。此外,您将无法匹配 SSIS 在管理其用于高吞吐量数据流的缓冲区方面的改进。

于 2010-07-15T01:52:04.870 回答
2

最初我希望将此过程放入某种接受 IEnumerable 列表的 CLR 程序集中,因为我已经有了这种形式的电子表格,但我最近了解到这将与一个相当重要的数据库服务器配对,我我非常担心陷入困境。

不工作。对 C# 编写的 CLR 过程的任何输入仍然必须遵循正常的 SQL 语义。所有可以改变的是内部设置。与客户端的任何通信都必须在 SQL 中完成。这意味着执行/方法调用。无法直接传入可枚举的对象。

于 2010-07-15T01:26:26.273 回答
1

My plan is/was to create an object modeling the spreadsheet, parse the data into it and use LINQ to do some checks client side before sending the data to the server... Basically I need to compare the data in the sheet to a matching record (Unless none exist, then its new). If any of the fields have been altered I want to send the update.

You probably need to pick a "centricity" for your approach - i.e. data-centric or object-centric.

I would probably model the data appropriately first. This is because relational databases (or even non-normalized models represented in relational databases) will often outlive client tools/libraries applications. I would probably start trying to model in a normal form and think about the triggers to maintain audit/history as you mention during this time also.

I would typically then think of the data coming in (not an object model or an entity, really). So then I focus on the format and semantics of the inputs and see if there is misfit in my data model - perhaps there were assumptions in my data model which were incorrect. Yes, I'm not thinking of making an object model which validates the spreadsheet even though spreadsheets are notoriously fickle input sources. Like Remus, I would simply use SSIS to bring it in - perhaps to a staging table and then some more validation before applying it to production tables with some T-SQL.

Then I would think about a client tool which had an object model based on my good solid data model.

Alternatively, the object approach would mean modeling the spreadsheet, but also an object model which needs to be persisted to the database - and perhaps you now have two object models (spreadsheet and full business domain) and database model (storage persistence), if the spreadsheet object model is not as complete as the system's business domain object model.

I can think of an example where I had a throwaway external object model kind of like this. It read a "master file" which was a layout file describing an input file. This object model allowed the program to build SSIS packages (and BCP and SQL scripts) to import/export/do other operations on these files. Effectively it was a throwaway object model - it was not used as the actual model for the data in the rows or any kind of navigation between parent and child rows, etc., but simply an internal representation for internal purposes - it didn't necessarily correspond to a "domain" entity.

于 2010-07-15T02:19:13.713 回答