0

I have an application that detects data changes of an AJAX driven WebBrowser control and then stores these transactions in a normalized database.

The normalized data model has 4, one-to-many keyed tables and when thinking about the write / insert, it occurred to me that there may be a time-tested design pattern for this.

Each data object can contain 3 data elements that would be repeated in a non-normalized or flatten database.

Would I need to search all three tables to determine if a record already exists before inserting a unique data element in a new table record from the transaction?

Is there a C# class in MS .NET, MFC or LINQ that;

  1. simplifies the coding
  2. improves the performance or
  3. implements a best-in-class design pattern?

I've searched the pattern libraries and have not seen anything yet.

1 Answer 1

0

Yes! I ran into a similar issue and used XML for the insert.

.NET has some awesome built-in XML functions, so it should (hopefully) be easy to turn your data into some kind of XML structure. Once you have that, you can pass it into the database via a single stored procedure parameter for insertion. Do all the checking within the stored procedure, rather than in your code.

Check out this article: http://weblogs.asp.net/jgalloway/archive/2007/02/16/passing-lists-to-sql-server-2005-with-xml-parameters.aspx

2
  • Thanks for the input. I've also looked into the OpenXML command in Transact-SQL.
    – robWDC
    Feb 13, 2012 at 13:49
  • The "key" challenge here is inserting data into child tables where a record already exists and the key to this record should be used when parsing the flattened (non-normalized) record into the parent table. Further research indicates that LINQ does not support bulk inserts/updates. One interesting technique describes loading the flattened array into a temporary table and then use Transact-SQL to parse the data into the respective parent and child tables. Not being a T-SQL expert, I was looking for either code or patterns that have already been implemented and tested.
    – robWDC
    Feb 13, 2012 at 13:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.