Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

Json and Entity Framework Cannot return from multiple table

$
0
0

Hello

I have several tables which I read the data from them and set it into a View Class 

All of models are defined as IList expect the EmployeeProfile Table. 

I have relation between Employeeprofile and Nationalities, Positions, Salaries, etc.... 

I can get the data if I only select Employee Profile data like below 

 var EProfile = _context.EmployeeProfile.SingleOrDefault(x => x.id== id);

If I include table like Positions to get the title of the position, I can't get the result 

 var EProfile = _context.EmployeeProfile.include(x=> x.position).SingleOrDefault(x => x.Eid == id);

if define Positions in the ViewClass , it will not work too , I tried both as list or single object 

_context.Positions.SingleOrDefault(x => x.PositionsId == EProfile.PositionsId);

_context.Positions.Tolist();

I used the below as return 

return new ObjectResult(ViewClass);

and this 

return Json(new { data = ViewClass});

both returns EmployeeProfile only and If Include any other table, it will not work

I am using postman to test the Json

By the way it is working in Chrome

I am doing this to use the data in Stimulsoft report 

Thanks in Advance


Viewing all articles
Browse latest Browse all 1698

Trending Articles