【发布时间】:2020-01-22 02:50:46
【问题描述】:
我有以下映射:
public class TimeLineEntityMap : BaseEntityMap<TimeLineEntity>
{
public TimeLineEntityMap()
{
Table("time_line_entity");
Map(x => x.Message);
Map(x => x.ResearchId, "research_id");//.Cascade.All().Not.LazyLoad();
ReferencesAny(x => x.EntityRef)
.AddMetaValue<EmailEntity>(typeof(EmailEntity).Name)
.AddMetaValue<UrlEntity>(typeof(UrlEntity).Name)
.AddMetaValue<PhoneEntity>(typeof(PhoneEntity).Name)
.EntityTypeColumn("entity_type")
.IdentityType<long>()
.EntityIdentifierColumn("entity_ref_id")
.Not.LazyLoad();
}
}
当从数据库中获取 EntityRef 时,它是一个代理。
TimeLineEntity res = timeLineRepository.Find(x => x.Id == id);
JsonConvert.SerializeObject(res);
JsonConvert 正在投掷:
Newtonsoft.Json.JsonSerializationException: Self referencing loop detected for property 'ManifestModule' with type 'System.Reflection.RuntimeModule'. Path 'Data[0].EntityRef._proxyFactoryInfo._getIdentifierMethod.Module.Assembly'.
这是我的 json 设置:
x.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
x.SerializerSettings.ContractResolver = new NHibernateContractResolver();
public class NHibernateContractResolver : CamelCasePropertyNamesContractResolver
{
protected override JsonContract CreateContract(Type objectType)
{
if (typeof(NHibernate.Proxy.INHibernateProxy).IsAssignableFrom(objectType))
return base.CreateContract(objectType.BaseType);
else
return base.CreateContract(objectType);
}
}
【问题讨论】:
-
那么你的问题是什么?
-
@AmirChristian 查看异常消息
-
请分享您的模型类..
-
你需要jsonignore
标签: json nhibernate