Navigation


Milos Solution Platform (External Blog)

The Milos Solution Platform is .NET's premier platform for building business applications. This blog is meant for developers who use or evaluate Milos. This blog is used to share tidbits of information provided by the Milos developers at EPS. Many of the posts put the spotlight on new features. We generally recommend that all Milos users (developers) at least scan this blog to keep up with the Milos news.

Content Area Footer

Saturday, October 13, 2007
'Split-Table' Table Updated

Here is a new feature that only some people will need, but those who need it really do... ;-)

The Milos BusinessObject class features a SaveTable() method, with takes a DataTable as a parameter (among other things) and can then (by means of using various DataService features) simply persist all the changes in the data table back to the database server (whether that's SQL Server or some other database technology). This feature is used extensively by the BusinessEntity infrastructure (among other things). So for instance, when you load a business entity that has a master table and several child tables, each of the tables inside the entity is saved using the SaveTable() method.

However, it has been brought to our attention that people sometimes like to load tables into entities or DataSets that are not just simple tables, but they may be created by joins that incorporate multiple tables. In that case the SaveTable() method was not able to save the table, since every record in the DataTable really mapped to different tables in the database. We have now added a feature to Milos that can handle this scenario in many (although not all!) cases. The basic idea is this: We provide a new SaveTable() overload with parameters that allow you to indicate which fields to include in the save operation, and what the table name maps to, and even field maps in case some of the fields are renamed.

So let's say you created a join that returned a table that has fields from a Contacts table, such as ContactID (maps to ID), FirstName, LastName, and also fields from a 1:1 joined CustomerInformation table like CustomerID (maps to ID), CustomerNumber and CreditLimit. You could save this information back to the database in a two-step operation, like so:

string[] contactFields =
    new string[] { "ContactID", "FirstName", "LastName" };
Dictionary<string, string> contactFieldMaps =
    new Dictionary<string, string>();
fieldMaps.Add("ContactID", "ID");
bool retVal = this.SaveTable(
    existingDataSet.Tables["CustInfo"], "ID",
    "Contacts", contactFields, contactFieldMaps, false);

if (retVal)
{
    string[] contactFields = new string[]
        { "CustomerID", "CustomerNumber", "CreditLimit" };
    Dictionary<string, string> contactFieldMaps =
        new Dictionary<string, string>();
    fieldMaps.Add("CustomerID", "ID");
    bool retVal = this.SaveTable(
        existingDataSet.Tables["CustInfo"], "ID",
        "CustomerInformation", contactFields,
        contactFieldMaps, true);
}

In this example, the first SaveTable() operation is limited to the ContactID, FirstName, and LastName fields. Also, the primary key for the Contacts table is really ID, so we create a map for that. (This works for all fields, not just primary keys). If that save is successful, we perform a second save operation for the remaining fields. Not that in the second operation, we pass a true as the last parameter, which flags the data table as unchanged in memory (this is not done after the first save, since other changes still exist).

So this works nicely, but there are a few things you need to know. First, this works best if the table contains 1:1 relationship data. In one-to-many scenarios, the parent "record" exists multiple times, and thus really shouldn't be updated. You can still use the same functionality to update the information from the second part of the table, but you should be very careful updating the parent information, since it will potentially result in multiple updates that can each override each other. Another potential issue is that in memory, each record only has one record state. So the record is either flagged as unchanged, deleted, modified, or added. However, if the parent-part is modified, but the child-part should be considered added, then that would not work and the generated update statements would be incorrect and potentially fail, or - worse - cause incorrect data to be written to the database. So be careful with that.

One aspect of this that isn't immediately obvious is that this new functionality can also be used in scenarios where you just query a single table, but the update needs to map field names, or limit the update to certain fields. For instance, if an empty string array of field names is passed to this method and a mapping dictionary is passed, then all fields will be saved, but they can be mapped. Or, you can pass an empty dictionary, but pass a limiting list of field names, to exclude certain fields from update. Both scenarios can be very useful in a number of scenarios.

 

Posted @ 11:48 AM by Egger, Markus (markus@code-magazine.com) -
Comments (11)




Comments:

RE: 'Split-Table' Table Updated
Tuesday, June 21, 2011 10:39 PM by new era - vsg@gcv.com

you for taking the time to publish this information very useful!


RE: 'Split-Table' Table Updated
Friday, June 24, 2011 12:54 PM by paul smith pas cher - 82346878@qq.com

Bulk sequence is stored on reels. When a shopper buys a certain chunk of connect from the manufacturer, the yardage is cut and wound on a minor whirl, which is located in synthetic bags for shipping.


RE: 'Split-Table' Table Updated
Wednesday, June 29, 2011 7:27 PM by vibram 5 fingers - cai297472630@126.com

Great job on the blog, it looks great. I am going to save it and will make sure to visit weekly


it’s
Tuesday, July 05, 2011 9:21 PM by shaun t insanity - 1421360297@qq.com

it’s an effective information I found in this article. It has good worth to share with others. Will definitely take this in consideration.


RE: 'Split-Table' Table Updated
Tuesday, November 08, 2011 6:53 PM by iPhone 4S Ringtone Maker - plant2013@gmail.com

iPhone 4S Ringtone Maker is the fastest and easiest way to create custom ringtones for your iPhone.


Asics Onitsuka
Thursday, December 01, 2011 9:36 PM by Asics Onitsuka - asicsshoes@gmail.com

good post!!


RE: 'Split-Table' Table Updated
Tuesday, December 20, 2011 4:13 PM by Artikel Spinning Software - agehg@yahoo.com

While we were at it, we made a few small improvements, such as a straightforward way to set the minimum required Silverlight version to 3.0.


RE: 'Split-Table' Table Updated
Wednesday, December 28, 2011 5:58 AM by Android app developers - suchismit.panda1989@gmail.com

I like your blog details.This is one of the developing post.Your blog is creating a good blog posting Environment.


RE: 'Split-Table' Table Updated
Friday, December 01, 2017 11:23 PM by phd dissertation writing service - neiljakson105@gmail.com

Once you have a table in Word, you might decide to split that table into two or more tables. This way, you can create smaller tables, or add text in between two tables. Put your cursor on the row that you want as the first row of your second table. ... You can split the table further, as long as there are multiple rows.


RE: 'Split-Table' Table Updated
Tuesday, July 17, 2018 12:22 AM by online jobs - alvinaash873@gmail.com

Here you can read about how to get Online Jobs In USA At Home without investment. In the fast life of today, everyone likes to multitask. Students want to.


RE: 'Split-Table' Table Updated
Friday, August 17, 2018 2:51 AM by http://www.topbritishessays.com/brillassignment-co-uk-review

The information regarding the table is quite complicated when compared to others ,so we have to calculate carefully ,reading each time every table.I found an article recently where one table can effect another one.




Post a Comment:

Comment Title (required)

Your Name (optional)

Your Email (optional)

Your Web Site (optional)

Your Comment (required)

 

 

 

 

 

 

 

Syndication RSS 2.0 RSS 2.0

All My Blogs:
My personal blogs:
Dev and Publishing Dev and Publishing
Travel and Internat. Living Travel and Internat. Living
Other blogs I contribute to:
Milos Blog (US) Milos Blog (US)
VFPConv. Dev Blog (US) VFPConv. Dev Blog (US)
VFPConv. Dev Blog (DE) VFPConv. Dev Blog (DE)

 

Blog Archives
All Blog Posts

2010
    November (1)
2009
    July (2)
    February (2)
    January (1)
2008
    December (1)
    October (3)
    June (1)
    April (3)
    February (1)
    January (1)
2007
    December (1)
    October (2)
    September (2)
    July (1)
    June (2)
    May (4)
    April (6)
    March (8)
    February (3)
    January (2)
2006
    December (2)
    November (2)

 

 

 

This Blog is powered by MilosTM Collaboration Components.