codesmithtools / Templates

CodeSmith Generator Templates
http://www.codesmithtools.com/product/generator
54 stars 35 forks source link

PLINQO - TimeSpan serialization breaks DataContext.LastAudit.ToXml() #662

Closed GoogleCodeExporter closed 4 years ago

GoogleCodeExporter commented 9 years ago
REPRODUCE:
1. Create a table that has one or more time(7) columns 
2. Set Entities.AuditingEnabled = true
3. Generate classes (time(7) will be generated as TimeSpan)
4. Insert an object with the TimeSpan set and SubmitChanges()
5. Call DataContext.LastAudit.ToXml();

EXPECTED: Audit data in xml format
ACTUAL: Exception thrown - "The type System.TimeSpan was not expected. Use the 
XmlInclude or SoapInclude attribute to specify types that are not known 
statically"

VERSION: PLINQO, CodeSmith.Data 5.0.1.1966

WORK AROUND:
Add a class as follows;
public static object FormatTimeSpan(MemberInfo memberInfo, object value)
{
     var t = value as TimeSpan?;
     if (t == null || !t.HasValue)
         return value;
     return System.Xml.XmlConvert.ToString(t.Value);
}

and place the following data annotation above TimeSpan properties in an 
Entity's partial, Metadata class;

[AuditPropertyFormat(typeof(CustomAuditFormat),"FormatTimeSpan")]

Original issue reported on code.google.com by stafford...@gmail.com on 30 Jul 2012 at 1:34

GoogleCodeExporter commented 9 years ago

Original comment by bniemyjski on 30 Jul 2012 at 1:37

stale[bot] commented 4 years ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. This issue now has been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.