У меня есть следующее сопоставление:
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);
}
}