G
germ
I was playing with some mutable/immutable stuff and came across something
that is not what I expected.
Given the classes and the ObjectDataSource below, I would have expected an
error due to readonly properties when attempting an update using a databound
control with using this ods
But this isn't the case - the ODS seems to be finding the base class
property definitions rather than those of the actual class that is being
used.
If I change the names of the base class properties or drop the base class
altogether then I get the expected behaviour.
I had expected to have 2 sets of crud methods on the objManager - general
use using immutableObj and ODS specific using mutableObj. It looks like the
mutable versions aren't required.
I'm not sure if this is a good thing or not.
Is there anyway to get the ODS to respect the class definition as specified
by DataObjectTypeName ?
I read an article stating that objects that are completely readonly are
handled more efficiently but the runtime. Does this apply to the
immutableObj class ? Strictly speaking it is 100% readonly but its base
class isn't and it also isn't directly accessible as all properties are
new'd in the derived class. My guess is that this is not considered a
readonly class.
Gerry
// mutable base - ObjectDataSource finds these properties which are settable
public class mutableObj
{
static int _id = 0;
public int ID { get; set; }
public string Name { get; set; }
public string Title { get; set; }
public mutableObj()
{
ID = ++_id;
Name = string.Format( "Obj {0} Name" , ID );
Title = string.Format( "Obj {0} Title" , ID );
}
}
// in general we want these objects to be immutable
public class immutableObj : mutableObj
{
new public int ID { get { return base.ID; } }
new public string Name { get { return base.Name; } }
new public string Title { get { return base.Title; } }
public immutableObj ()
:base()
{
}
public immutableObj ( int ID , string Name , string Title )
{
base.ID = ID;
base.Name = Name;
base.Title = Title;
}
}
public static class objManager
{
private static immutableObj [] Objects= {
new immutableObj () ,
new immutableObj () ,
new immutableObj () ,
new immutableObj () ,
};
public static immutableObj [] Select() { return Objects; }
public static void Update( immutableObj dat ) {}
}
<asp:ObjectDataSource runat="server"
ID="ObjODS"
TypeName="objManager"
SelectMethod="Select"
UpdateMethod="Update"
DataObjectTypeName="immutableObj "
/>
that is not what I expected.
Given the classes and the ObjectDataSource below, I would have expected an
error due to readonly properties when attempting an update using a databound
control with using this ods
But this isn't the case - the ODS seems to be finding the base class
property definitions rather than those of the actual class that is being
used.
If I change the names of the base class properties or drop the base class
altogether then I get the expected behaviour.
I had expected to have 2 sets of crud methods on the objManager - general
use using immutableObj and ODS specific using mutableObj. It looks like the
mutable versions aren't required.
I'm not sure if this is a good thing or not.
Is there anyway to get the ODS to respect the class definition as specified
by DataObjectTypeName ?
I read an article stating that objects that are completely readonly are
handled more efficiently but the runtime. Does this apply to the
immutableObj class ? Strictly speaking it is 100% readonly but its base
class isn't and it also isn't directly accessible as all properties are
new'd in the derived class. My guess is that this is not considered a
readonly class.
Gerry
// mutable base - ObjectDataSource finds these properties which are settable
public class mutableObj
{
static int _id = 0;
public int ID { get; set; }
public string Name { get; set; }
public string Title { get; set; }
public mutableObj()
{
ID = ++_id;
Name = string.Format( "Obj {0} Name" , ID );
Title = string.Format( "Obj {0} Title" , ID );
}
}
// in general we want these objects to be immutable
public class immutableObj : mutableObj
{
new public int ID { get { return base.ID; } }
new public string Name { get { return base.Name; } }
new public string Title { get { return base.Title; } }
public immutableObj ()
:base()
{
}
public immutableObj ( int ID , string Name , string Title )
{
base.ID = ID;
base.Name = Name;
base.Title = Title;
}
}
public static class objManager
{
private static immutableObj [] Objects= {
new immutableObj () ,
new immutableObj () ,
new immutableObj () ,
new immutableObj () ,
};
public static immutableObj [] Select() { return Objects; }
public static void Update( immutableObj dat ) {}
}
<asp:ObjectDataSource runat="server"
ID="ObjODS"
TypeName="objManager"
SelectMethod="Select"
UpdateMethod="Update"
DataObjectTypeName="immutableObj "
/>