You don't really need a hard code example? Basically, imagine something
like:

var myActiveRecordObjectThatWontSerialize = GetNewInstance();
var simpleDTO = new SimpleDTOThatSerializes();

simpleDTO.Field1 = myActiveRecordObjectThatWontSerialize.Field1;
simpleDTO.Field2 =
myActiveRecordObjectThatWontSerialize.NestedObject.Field2;

etc...you could also possibly use AutoMapper or something like that to kind
of automate how that gets done.

SimpleDTOThatSerializes is something like:

public class SimpleDTOThatSerializes
{
      public string Field1 { get; set; }
      public string Field2 { get; set; }
}

Hope that helps...

Eric

On Fri, Mar 30, 2012 at 9:14 PM, Jose Pino <[email protected]> wrote:

> El jue, 29-03-2012 a las 21:18 -0700, Eric Tarasoff escribió:
> > You might not like this answer but in situations like this, or even in
> > Ajax situations, we use DTOs. Serializing complex object graphs (or
> > even not so complex ones) always seems to be problematic.
>
> you have any example to use DTO, link, code...with ActiveRecord
>
>
> thanks
>
>
> >
> > On Thu, Mar 29, 2012 at 8:54 PM, Joil <[email protected]> wrote:
> >         Hi people, I have a problem with Relations mapping exposed in
> >         a Web Service
> >
> >         Model
> >
> >         [ActiveRecord]
> >             public class Ticket : ActiveRecordValidationBase<Ticket>
> >             {
> >                 private IList _followup = new ArrayList();
> >
> >                 [PrimaryKey(PrimaryKeyType.Native)]
> >                 public int Id {
> >                     get; set;
> >                 }
> >                 ...
> >                 ...
> >                 [HasMany(typeof(Followup), Inverse = true,
> >         Table="Followup", ColumnKey="TicketId")]
> >                 public IList Followups
> >                 {
> >                     get { return _followup; }
> >                     set { _followup = value; }
> >                 }
> >             }
> >
> >         [ActiveRecord]
> >             public class Followup :
> >         ActiveRecordValidationBase<Followup>
> >             {
> >                 private Ticket _ticket;
> >
> >                 [PrimaryKey(PrimaryKeyType.Native)]
> >                 public int Id {
> >                     get; set;
> >                 }
> >                 ...
> >                 ...
> >                 [BelongsTo("TicketId")]
> >                 public Ticket TicketRef
> >                 {
> >                     get { return _ticket; }
> >                     set { _ticket = value; }
> >                 }
> >             }
> >
> >
> >         Web Serbice
> >
> >             public class ws : System.Web.Services.WebService
> >             {
> >                 [WebMethod()]
> >                 public Ticket[] ListAllTicket() {
> >                     return (Ticket[]) Ticket.FindAll(typeof(Ticket));
> >                 }
> >             }
> >
> >
> >         Error Invoke WebMethod, output :
> >
> >         500 - Internal Server Error
> >         System.InvalidOperationException: There was an error
> >         generating the XML document. --->
> >         System.InvalidOperationException: A circular reference was
> >         detected while serializing an object of type Ticket
> >           at
> >
> System.Xml.Serialization.XmlSerializationWriter.WriteStartElement
> (System.String name, System.String ns, System.Object o, Boolean
> writePrefixed, ICollection namespaces) [0x00000] in <filename unknown>:0
> >           at
> >
> System.Xml.Serialization.XmlSerializationWriter.WriteStartElement
> (System.String name, System.String ns, System.Object o, Boolean
> writePrefixed) [0x00000] in <filename unknown>:0
> >           at
> >
> System.Xml.Serialization.XmlSerializationWriter.WriteStartElement
> (System.String name, System.String ns, System.Object o) [0x00000] in
> <filename unknown>:0
> >           at
> >
> System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteObject
> (System.Xml.Serialization.XmlTypeMapping typeMap, System.Object ob,
> System.String element, System.String namesp, Boolean isNullable, Boolean
> needType, Boolean writeWrappingElem) [0x00000] in <filename unknown>:0
> >           at
> >
> System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteMemberElement
> (System.Xml.Serialization.XmlTypeMapElementInfo elem, System.Object
> memberValue) [0x00000] in <filename unknown>:0
> >           at
> >
> System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteElementMembers
> (System.Xml.Serialization.ClassMap map, System.Object ob, Boolean
> isValueList) [0x00000] in <filename unknown>:0
> >           at
> >
> System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteObjectElementElements
> (System.Xml.Serialization.XmlTypeMapping typeMap, System.Object ob)
> [0x00000] in <filename unknown>:0
> >           at
> >
> System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteObjectElement
> (System.Xml.Serialization.XmlTypeMapping typeMap, System.Object ob,
> System.String element, System.String namesp) [0x00000] in <filename
> unknown>:0
> >           at
> >
> System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteObject
> (System.Xml.Serialization.XmlTypeMapping typeMap, System.Object ob,
> System.String element, System.String namesp, Boolean isNullable, Boolean
> needType, Boolean writeWrappingElem) [0x00000] in <filename unknown>:0
> >           at
> >
> System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteMemberElement
> (System.Xml.Serialization.XmlTypeMapElementInfo elem, System.Object
> memberValue) [0x00000] in <filename unknown>:0
> >           at
> >
> System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteListContent
> (System.Object container, System.Xml.Serialization.TypeData listType,
> System.Xml.Serialization.ListMap map, System.Object ob,
> System.Text.StringBuilder targetString) [0x00000] in <filename unknown>:0
> >           at
> >
> System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteMemberElement
> (System.Xml.Serialization.XmlTypeMapElementInfo elem, System.Object
> memberValue) [0x00000] in <filename unknown>:0
> >           at
> >
> System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteElementMembers
> (System.Xml.Serialization.ClassMap map, System.Object ob, Boolean
> isValueList) [0x00000] in <filename unknown>:0
> >           at
> >
> System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteObjectElementElements
> (System.Xml.Serialization.XmlTypeMapping typeMap, System.Object ob)
> [0x00000] in <filename unknown>:0
> >           at
> >
> System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteObjectElement
> (System.Xml.Serialization.XmlTypeMapping typeMap, System.Object ob,
> System.String element, System.String namesp) [0x00000] in <filename
> unknown>:0
> >           at
> >
> System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteObject
> (System.Xml.Serialization.XmlTypeMapping typeMap, System.Object ob,
> System.String element, System.String namesp, Boolean isNullable, Boolean
> needType, Boolean writeWrappingElem) [0x00000] in <filename unknown>:0
> >           at
> >
> System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteMemberElement
> (System.Xml.Serialization.XmlTypeMapElementInfo elem, System.Object
> memberValue) [0x00000] in <filename unknown>:0
> >           at
> >
> System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteListContent
> (System.Object container, System.Xml.Serialization.TypeData listType,
> System.Xml.Serialization.ListMap map, System.Object ob,
> System.Text.StringBuilder targetString) [0x00000] in <filename unknown>:0
> >           at
> >
> System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteListElement
> (System.Xml.Serialization.XmlTypeMapping typeMap, System.Object ob,
> System.String element, System.String namesp) [0x00000] in <filename
> unknown>:0
> >           at
> >
> System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteObject
> (System.Xml.Serialization.XmlTypeMapping typeMap, System.Object ob,
> System.String element, System.String namesp, Boolean isNullable, Boolean
> needType, Boolean writeWrappingElem) [0x00000] in <filename unknown>:0
> >           at
> >
> System.Xml.Serialization.XmlSerializationWriterInterpreter.WriteRoot
> (System.Object ob) [0x00000] in <filename unknown>:0
> >           at System.Xml.Serialization.XmlSerializer.Serialize
> >         (System.Object o,
> >         System.Xml.Serialization.XmlSerializationWriter writer)
> >         [0x00000] in <filename unknown>:0
> >           at System.Xml.Serialization.XmlSerializer.Serialize
> >         (System.Xml.XmlWriter writer, System.Object o,
> >         System.Xml.Serialization.XmlSerializerNamespaces namespaces)
> >         [0x00000] in <filename unknown>:0
> >           --- End of inner exception stack trace ---
> >           at System.Xml.Serialization.XmlSerializer.Serialize
> >         (System.Xml.XmlWriter writer, System.Object o,
> >         System.Xml.Serialization.XmlSerializerNamespaces namespaces)
> >         [0x00000] in <filename unknown>:0
> >           at System.Xml.Serialization.XmlSerializer.Serialize
> >         (System.Xml.XmlWriter xmlWriter, System.Object o) [0x00000] in
> >         <filename unknown>:0
> >           at System.Web.Services.Protocols.XmlReturnWriter.Write
> >         (System.Web.HttpResponse response, System.IO.Stream
> >         outputStream, System.Object returnValue) [0x00000] in
> >         <filename unknown>:0
> >           at
> >
> System.Web.Services.Protocols.HttpSimpleWebServiceHandler.ProcessRequest
> (System.Web.HttpContext context) [0x00000] in <filename unknown>:0
> >
> >
> >
> >         Any idea, how to fix ?
> >
> >
> >
> >
> >
> >
>
> --
> You received this message because you are subscribed to the Google Groups
> "Castle Project Users" group.
> To post to this group, send email to [email protected]
> .
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/castle-project-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en.

Reply via email to