Hi,
I have a problem with reverse association between the classes Address and City.
[Serializable]
[System.CodeDom.Compiler.GeneratedCode("LightSpeedModelGenerator", "1.0.0.0")]
[System.ComponentModel.DataObject]
[Table(IdColumnName = "Id", IdentityMethod = IdentityMethod.IdentityColumn)]
[DataContract(IsReference = true)]
public class Address : Entity<int>
{
private readonly EntityHolder<City> _City = new EntityHolder<City>();
}
[Serializable]
[System.CodeDom.Compiler.GeneratedCode("LightSpeedModelGenerator", "1.0.0.0")]
[System.ComponentModel.DataObject]
[Table(IdColumnName = "Id", IdentityMethod = IdentityMethod.IdentityColumn)]
[DataContract(IsReference = true)]
public class City : Entity<int>
{
private readonly EntityHolder<Address> _Address = new EntityHolder<Address>();
private int _AddressId;
}
look at error:
{
"Message": "An error has occurred.",
"ExceptionMessage": "The 'ObjectContent`1' type failed to serialize the response body for content type 'application/json; charset=utf-8'.",
"ExceptionType": "System.InvalidOperationException",
"StackTrace": null,
"InnerException": {
"Message": "An error has occurred.",
"ExceptionMessage": "Self referencing loop detected with type 'BeagleApp.Address'. Path '_City._valueChanged'.",
"ExceptionType": "Newtonsoft.Json.JsonSerializationException",
}
when I add this code:
config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
look at the mess:
{
"_PessoaId": 1,
"_CityId": 1,
"_Logradouro": "RUA CURUPACE",
"_Numero": "635",
"_Cep": 3120010,
"_Bairro": "MOOCA",
"_Complemento": "APTO 61F",
"_City": {
**"_proxiedCollection": null,**
"_value": {
**"$id": "1",**
"_Descricao": "LEME",
"_siglaUF": "SP",
"Id": 1
},
**"_isLazy": false,
"_isInCascadingChange": false,
"_valueChanged": {
"Delegate": {
"type": "System.EventHandler`1[[Mindscape.LightSpeed.EntityHolderValueCascadeChangedEventArgs, Mindscape.LightSpeed, Version=5.0.2597.0, Culture=neutral, PublicKeyToken=360c8f37b466ebb2]]",
"assembly": "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
"target": "target0",
"targetTypeAssembly": "Mindscape.LightSpeed, Version=5.0.2597.0, Culture=neutral, PublicKeyToken=360c8f37b466ebb2",
"targetTypeName": "Mindscape.LightSpeed.Entity",
"methodName": "HolderValueCascadeChangedEvent",
"delegateEntry": null
},
"method0": {
"Name": "HolderValueCascadeChangedEvent",
"AssemblyName": "Mindscape.LightSpeed, Version=5.0.2597.0, Culture=neutral, PublicKeyToken=360c8f37b466ebb2",
"ClassName": "Mindscape.LightSpeed.Entity",
"Signature": "Void HolderValueCascadeChangedEvent(System.Object, Mindscape.LightSpeed.EntityHolderValueCascadeChangedEventArgs)",
"Signature2": "System.Void HolderValueCascadeChangedEvent(System.Object, Mindscape.LightSpeed.EntityHolderValueCascadeChangedEventArgs)",
"MemberType": 8,
"GenericArguments": null**
}
}
},
"Id": 1
}
any advice and suggestions will be greatly appreciated.
tks