Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# JsonetResult未返回S#arp Nhibernate对象_C#_Jquery_Asp.net Mvc_S#arp Architecture - Fatal编程技术网

C# JsonetResult未返回S#arp Nhibernate对象

C# JsonetResult未返回S#arp Nhibernate对象,c#,jquery,asp.net-mvc,s#arp-architecture,C#,Jquery,Asp.net Mvc,S#arp Architecture,当一个对象是另一个对象的属性时,我在返回该对象的JsonNetResult时遇到问题,但是当我显式地获取该对象时,它会工作,例如 JsonNetResult res = new JsonNetResult(); res.Formatting = Formatting.Indented; res.SerializerSettings.NullValueHandling = NullValueHandling.Ignore; res.Data = addressRepository

当一个对象是另一个对象的属性时,我在返回该对象的JsonNetResult时遇到问题,但是当我显式地获取该对象时,它会工作,例如

JsonNetResult res = new JsonNetResult();  
 res.Formatting = Formatting.Indented;  
 res.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;  
 res.Data = addressRepository.Get(7);  
 return res;
但是返回一个有效的结果

JsonNetResult res = new JsonNetResult();  
res.Formatting = Formatting.Indented;  
res.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;  
res.Data = businessRepository.Get(businessID).Address;  
return res;
将返回一个空对象;当然

JsonNetResult res = new JsonNetResult();  
res.Formatting = Formatting.Indented;  
res.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
res.Data =  addressRepository.Get(businessRepository.Get(businessID).Address.Id);  
return res;`
即使地址和ID在每种情况下都完全相同。
有什么明显的地方我遗漏了吗?

这听起来像是一个延迟加载问题,在尝试水合Json对象时会发生这种情况。address属性是字符串还是引用其他对象?确保没有递归引用,尽管JsonNetResult应该处理这个问题

进入实体的映射并添加以下内容:

mapping.References(x => x.Address).Not.LazyLoad();

这将从等式中删除任何延迟加载代理。

澄清一下:您是否在调试器中查看了这一点,并确定
businessRepository.Get(businessID).Address
返回了您实际需要的正确对象?调试器在赋值后立即对
res.Data
的值做了什么说明?查看调试器时,对象看起来完全相同,只是不起作用的对象有一个名为“HibernateLazyInitializer”的属性。谢谢。我想我不能将懒散加载与Json结合起来