Hi all, this hopefully extends the talk a couple months ago on DTO's embedded in business objects.
We have adopted the idea of a DTO as a class (like Rocky mentioned) that is used by BO's privately for db data. All properties in BO actually expose the fields in the DTO class (except for child collections). We also used Petar's idea of attributes to enable auto sql fetching/population via reflection so I never have to write a sql statement manually (well worth it). Simple example below.
<Serializable(), DBTable(
"JTRep")> _ Friend Class JTRepVariables<DBPrimaryKey(
"RepID")> Friend mRepID As String = JTMisc.JTGeneral.getNewGUID<DBRequired(
"LastName")> Friend mLastName As String = ""<DBNullable(
"FirstName")> Friend mFirstName As String = ""<DBNullable(
"MiddleName")> Friend mMiddleName As String = ""<DBNullable(
"SSN")> Friend mSSN As String = ""<DBNullable(
"RecordActive")> Friend mRecordActive As Integer = 1<DBInsertAudit(
"InsertRepID")> Friend mInsertRepID As String = ""<DBInsertAudit(
"InsertDate")> Friend mInsertDate As New SmartDate<DBInsertAudit(
"InsertOSLogin")> Friend mInsertOSLogin As String = ""<DBInsertAudit(
"InsertMachineID")> Friend mInsertMachineID As String = ""<DBUpdateAudit(
"UpdateRepID")> Friend mUpdateRepID As String = ""<DBUpdateAudit(
"UpdateDate")> Friend mUpdateDate As New SmartDate<DBUpdateAudit(
"UpdateOSLogin")> Friend mUpdateOSLogin As String = ""<DBUpdateAudit(
"UpdateMachineID")> Friend mUpdateMachineID As String = ""<DBRequired(
"RowGuid")> Friend mRowGuid As Guid = Guid.NewGuid Public Overrides Function ToString() As String Return mLastName.Trim & ", " & mFirstName.Trim & " " & mMiddleName.Trim End Function End Class
So any flavor of a Rep object (of which we have probably 8 - 10) uses this internally and exposes properties appropriate to that use case. (ReadOnly, Editable, or Relationships) Editable Rep has an instance of RepVariables and exposes those appropriately as read/write whereas ReadOnly Rep only exposes the Rep Variables as readonly properties. This saved us quite a bit of work when we started building our objects that represented the many to many relationships.
Aside from feedback about this...Here is what I need help with. I need to write an importer that takes XML, validates it, and then hydrates a BO. This XML would be coming from external sources somewhere else in the enterprise. One particular scenario is that we will be exporting data to robots who perform tasks and then give us back ASCII files. Thos will be transformed (XSLT) into XMLa and then imported for being hydrated into business objects.
Should I make an XML schema that maps one to one to the DTO's we have defined? I don't want to reinvent the wheel and my gut says I can reuse what I already have somehow.
Thanks
Sean
couple questions then:
1. Would I just generate an xml schema based on one of my xmlserialized DTO's and use that as my contract with the outside then?
2. Where is the appropriate place to put the method reside that accepts the xml and translates it into a DTO?
3. You mention "serious consequences" on doing DTO's this way...curious what your thinking of there.
Sean
Copyright (c) Marimer LLC