This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
I have a WCF web service that returns Lightspeed entities, and I'm getting the following runtime error: System.Runtime.Serialization.InvalidDataContractException: 'Team2Service.ClientSession._startDt' is not marked with OptionalFieldAttribute, thus indicating that it must be serialized. However, 'Team2Service.ClientSession' derives from a class marked with DataContractAttribute and an IsReference setting of 'True'. It is not possible to have required data members on IsReference classes. Either decorate 'Team2Service.ClientSession._startDt' with OptionalFieldAttribute, or disable the IsReference setting on the appropriate parent class. do I need to add the OptionalField attribute to every field and property of every one of my entities to fix this? the DTO classes don't contain child objects that I want to return, so my choice is to either A: create partial classes to extend the existing DTO objects, and then implement the BeforeCopy and AfterCopy partial methods - not my first choice because it requires LOTS of extra work on my part. or B: make the entity classes fully serializable so I can return them through the WCF connection to the client.
I saw other posts referring to modifying templates so that the properties and fields would get automatically tagged with the OptionalField attribute when creating the model. where can I find these template files, and what changes do I need to make, if I decide to go this route? |
|
|
Hi, you dont need to specify the OptionalFieldAttribute, rather you need to mark up your entities with [DataContract] and [DataMember] attributes accordingly. If you are using the generator to generate your class definitions this will mean you will want to accordingly change the templates so that you dont lose changes from a regeneration. The reason for this is that the base entity class has a DataContract attribute with IsReference=true set on it (as indicated by the error you get) so you need to override this on your classes directly. We will look to have designer support for this in a future update but for now that is the workaround :)
Jeremy |
|
|
ok, this sounds pretty reasonable. where are the templates, and what do I need to change about them? |
|
|
I added [DataContract] and [DataMember] attributes to everything in my model, and now in some cases, the WCF methods never return, and I suspect, the system is trying to recurse too deeply through the objects. For example, I have an entity called ClientSession. It is composed of User, Site, and Station entities, and a User has a UserGroups collection, of which each UserGroup has a Site, which has a collection of UserGroups, and so on. Is there any way to restrict how deeply the serialization goes in the object tree for each entity? |
|