Reputation: 8646
I have following table structure in LINQ:
objective_id is foreign key in Resource table which is PK in Objective table.
I wanted to have output like this:
{
ID: '123',
user_id: '1',
skill_id:'1',
name:'abcs'
...
objective_resource:
{
ID: '123',
...
}
}
For this i tried:
using (DataTableClassesDataContext context = new DataTableClassesDataContext())
{
DataLoadOptions opts = new DataLoadOptions();
opts.LoadWith<objective_resource>(u => u.objective_id);
context.LoadOptions = opts;
return new JavaScriptSerializer().Serialize(context.objective_resources
.Where(u => u.id == 1)
);
}
But It given output:
{
ID: '123',
...
objective:
{
ID: '123',
user_id: '1',
skill_id:'1',
name:'abcs'
...
}
}
I wanted to have:
{
ID: '123',
user_id: '1',
skill_id:'1',
name:'abcs'
...
objective_resource:
{
ID: '123',
...
}
}
Please help me.
How can i get the output???
Upvotes: 2
Views: 140
Reputation: 238
make the change in association property in dbml file as
and write the code as
var data= dataContext.objectives;
return new JavaScriptSerializer().Serialize(data);
Upvotes: 1