<< Shooting Video on Green-screen SubSonic 2.1: Some Updated Fields Not Being Marked As Dirty >>

SubSonic 2.1: ObjectDataSource and DataObjectTypeName

Added Saturday, October 18, 2008 by Thevin Sattayatam, Developer · No Comments

When you specify the ObjectDataSource to use the controller and you assign a DataObjectTypeName instead of scripting out all the parameters. The template doesn’t handle a single parameter that is of the subsonic model object type.

Add the following to the Controller Template file (C# example):

Right after the current insert statement:

///
/// Inserts a record, can be used with the Object Data Source
///
[DataObjectMethod(DataObjectMethodType.Insert, true)]
public void Insert( Object)
{
Object.Save(UserName);
}

Right after the current update statement:

///
/// Updates a record, can be used with the Object Data Source
///
[DataObjectMethod(DataObjectMethodType.Update, true)]
public void Update( Object)
{
item = new ();
item.MarkOld();
item.CopyFrom(Object);
item.Save(UserName);
}

Please note that for the above scheme to work efficiently, ObjectDataSource caching is not being used or the instance of the record is not being loaded again from the db. I want to keep it lightweight. But I haven’t tested it with it caching enabled, on update you might be able to get away with:

///
/// Updates a record, can be used with the Object Data Source
///
[DataObjectMethod(DataObjectMethodType.Update, true)]
public void Update( Object)
{
Object.Save(UserName);
}

Leave a Reply

Comment