c# - How to force a query to retrieve nested elements data? -


i'm making json database made linq sql. i've set serialization mode unidirectional (so can serialize data), , once query object (user) convert json:

[webmethod] public user getuserbyid(int id) {     user user = db.user.where(p => p.id == id).firstordefault();     var json = jsonconvert.serializeobject(user, new isodatetimeconverter());     return user; } 

the problem on resulting json, nested data/objects (i.e. relationship have object others object/tables) null.

so, example, if have 3 phone numbers (1-n relationship) user, instead of retrieve json array these (3) numbers, puts:

"phones": null, 

how can "force" user queried data/relationship inside it?

and if query (for example) before serialize:

var phones = m_oalumno.telefono.tolist(); 

it says "self referencing loop detected type 'user'."

in linq sql can load referenced entities using dataloadoptions.

var loadoptions = new dataloadoptions(); loadoptions.loadwith<user>(u => u.phonenumber); db.loadoptions = loadoptions; 

where phonenumber entity references user , assuming db linq data context.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -