In my Web API controller, I return the results to a method call like so:
// GET api/profile/5
public VCompleteProjectProfile GetBasicProjectProfile(int id)
{
return _dbss.GetBasicProfile(id);
}
And here is the actual result:
{
"$id":"1",
"Id":1,
"ProjectName":"Caribbean Challenge",
"IsMrRcSelected":true,
"IsMrdProject":true,
"RegionName":"North America",
"EntityKey":{
"$id":"2",
"EntitySetName":"VCompleteProjectProfile",
"EntityContainerName":"MrdViewEntities",
"EntityKeyValues":[
{"Key":"Id","Type":"System.Int32","Value":"1"},
{"Key":"ProjectName","Type":"System.String","Value":"Caribbean Challenge"},
{"Key":"IsMrRcSelected","Type":"System.Boolean","Value":"True"}
]
}
}
Is it possible to suppress the EntityKey? If so, how? This is MVC4.
Thanks
Eric
Create a DTO/POCO for your result instead of returning the actual entity object e.g.
You could even extend your entity type to include a function called
ToDtowhich would do this for you e.g.A general rule of thumb is only return data that is needed, don’t cut corners just because it’s convenient.
Also, if you find yourself having to do this all over the place look at something like AutoMapper, will make your life a lot easier.