문제

I am having a problem returning a JsonNetResult for an object when it is a property of another object, however when I fetch the object explicitly it works e.g.

JsonNetResult res = new JsonNetResult();  
 res.Formatting = Formatting.Indented;  
 res.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;  
 res.Data = addressRepository.Get(7);  
 return res;

returns a valid result however

JsonNetResult res = new JsonNetResult();  
res.Formatting = Formatting.Indented;  
res.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;  
res.Data = businessRepository.Get(businessID).Address;  
return res;

will return an empty object; as will

JsonNetResult res = new JsonNetResult();  
res.Formatting = Formatting.Indented;  
res.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
res.Data =  addressRepository.Get(businessRepository.Get(businessID).Address.Id);  
return res;`

even though the address and it's ID is exactly the same in each situation. Is there something really obvious I'm missing?

도움이 되었습니까?

해결책

This sounds like a lazy-load problem, which happens when trying to hydrate Json objects. Is the address property a string or does it reference another object? Make sure there's no recursive references, though JsonNetResult should deal with that.

Go into your entity's mapping and add this:

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

That should take out any lazy load proxies out of the equation.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top