For some time, our most requested enhancement has been to support the serialization of SubSonic ActiveRecord objects. In the pre 1.0.5 days, SubSonic did support serialization, at the cost of not supporting null column values. Unfortunately, when we started using nullable types, we lost the ability to serialize any records that contained null column values, due to a decision the .NET team to not support serialization of the nullable types introduced 2.0 - presumably because of the pending serialization enhancements to be introduced with WCF.
That said, I'm pleased to announce that as of Revision 108 serialization support has returned via a new boolean provider configuration setting, generateNullableProperties. By default, this value is set to true. However, by setting it to false, the template generation behavior is changed to a variant of model that DevInstinct (Martin LaPierre) describes in a forums thread. By disabling the generation of nullable properties, the record can once again be serialized.
This is one of those cases where the code is probably clearer than any explanation I could give, so here goes.
With generateNullableProperties set to true (Default Behavior)
1 [XmlAttribute("SupplierID")]
2 public int? SupplierID
3 {
4 get { return GetColumnValue<int?>("SupplierID"); }
5 set
6 {
7 SetColumnValue("SupplierID", value);
8 }
9 }
With generateNullableProperties set to false (Serialization Supported)
1 [XmlAttribute("SupplierID")]
2 public int SupplierID
3 {
4 get
5 {
6 int? propSupplierID = GetColumnValue<int?>("SupplierID");
7 if (!propSupplierID.HasValue)
8 return 0;
9 return propSupplierID.Value;
10 }
11 set { SetColumnValue("SupplierID", value); }
12 }
13
14 [XmlIgnore]
15 public bool SupplierIDHasValue
16 {
17 get { return GetColumnValue<int?>("SupplierID") != null; }
18 set
19 {
20 int? propSupplierID = GetColumnValue<int?>("SupplierID");
21 if (!value)
22 SetColumnValue("SupplierID", null);
23 else if (value && !propSupplierID.HasValue)
24 SetColumnValue("SupplierID", 0);
25 }
26 }
Note that even when generateNullableProperties are set to false, nullable values are still supported, but are set via a new property of the same name with the suffix HasValue.
So give it a whirl, and let me know how it goes. As always, please post your bug reports here.