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
|
Getting this when serializing an entity into cache: The IsReference setting for type 'Mindscape.LightSpeed.Entity`1[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' is 'True', but the same setting for its parent class 'Mindscape.LightSpeed.Entity' is 'False'. Derived types must have the same value for IsReference as the base type. Change the setting on type 'Mindscape.LightSpeed.Entity`1[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' to 'False', or on type 'Mindscape.LightSpeed.Entity' to 'True', or do not set IsReference explicitly. Figured I should ask before poking around too hard.
|
|
|
Hi Luke, Ive made an update for this for tonights nightly build (20091224) if you want to give that a go. As a note, you will likely need to set the OptionalField attribute on the fields in your entity. Let us know how you get on.
Jeremy |
|
|
I have to set that attribute on every single member on every entity and remember to do it for every new member? Not sure if we can upgrade to LS3 then. How do you set that attribute for internalId? |
|
|
Nevermind about internalId. Looks like that's one of our things. |
|
|
Trying out the nightly, I get: 'Namespace.User._commentCount' is not marked with OptionalFieldAttribute, thus indicating that it must be serialized. However, 'Namespace.User' 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 'Namespace.User._commentCount' with OptionalFieldAttribute, or disable the IsReference setting on the appropriate parent class. CommentCount is a property of User. I can't add OptionalField to it because that attribute only applies to fields. That internalId thing mentioned above is a private transient field. Putting OptionalField on that worked. |
|
|
Hi Luke, Is _commentCount a field or a property? The serializer should only be complaining about fields, so OptionalField should be fine in each case.
Jeremy |
|
|
I believe _commentCount is the LS-created backing field for the CommentCount property. I can't add OptionalField to CommentCount because it's not a field. I'm pretty sure I don't want to go into the model.cs file and add the attribute to _commentCount since that's generated code. |
|
|
You will still need to add the OptionalField attribute to _commentCount to resolve this since the error refers to the field not the property. For generated code you can add the [OptionalField] declaration into the Fields.vm template (e.g. C:\Program Files\Mindscape\LightSpeed\Tools\Designer\Templates\C#\Fields.vm) to have it added to your generated output. I will raise this with the team in the New Year as something to add more direct support for in the designer since this is obviously something which should be covered. Suspect we will probably add a trigger such as having the System.Runtime.Serialization assembly referenced similar to our approach for generating DTO's or the typed UnitOfWork.
Jeremy |
|
|
There has to be a better solution to this than modifying the LightSpeed templates? Thanks, -Joe
|
|
|
Hi Joe, The reason for modifying the templates is if modification of the generated code is required, which in this case is likely to be required. As Luke highlighted earlier, there was a breaking change in 3.0 relating to DataContract based serialization if you were previously using .NET 3.5 SP1 attribute free serialization. We added a [DataContract] attribute for our DataServices support for the 3.5 based version (Mindscape.LightSpeed.dll). Generally if you want to serialize this for standard XML output, you will want to add a [DataContract] attribute to the entity and [DataMember] attributes accordingly to your properties. If you want to serialize with object references, then you can leave the existing DataContract attribute as defined and add the [OptionalField] attributes. If you are applying a namespace, you will also obviously need to redefine the DataContract attribute, or if you want to apply any fine grained control - if you already doing this then we would expect that you would not be impacted by this and have likely already modified templates if you are using the designer for code gen. As a note, there is a compatibility build of LightSpeed which ships alongside the primary assembly which still targets .NET 2.0 and as such does not include things such as the DataContract attribute on Entity, so you may find this of use depending on your situation. Hope that helps provide a bit more information on this.
Jeremy |
|