c# - Send relational data using Json to wcf services -


roles , privileges have relationship 1 many. while retrieving roles getting null value "[]" privileges. using json send data wcf services using ef6 having code first approach.

code :

system.web.script.serialization.javascriptserializer objjsserializer =       new system.web.script.serialization.javascriptserializer(); string strjson1 = objjsserializer.serialize((         role in  context.roles select role)        .tolist()); 

output:

[{"privileges":[],"users":[],"id":1,"rolename":"admin","isactive":1},

{"privileges":[],"users":[],"id":2,"rolename":"apprisal minister","isactive":0}]

i tried context.configuration.proxycreationenabled = false; still not able privileges.

basically, problem, getting when try serialize roles object. doesn't serialize relational data. mean privileges not there.

which right way relational data in entity framework6.

not sure if mean load roles , it's related privileges should work

var roles = dbcontext().roles.include(r => r.privileges); 

and serialize use newtonsoft.json ( nugget package ) handels relations not circular refs. if references in privileges roles , use attribute [jsonignore] on properties

 string json = jsonconvert.serializeobject(roles); 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -