I have an entity framework Complex Type(Activity) I have mapped to a SP which returns records of data.
class Activity
string viewed
string registered
I need to create another another EF entity (complex type?) that will hold metadata about this object and as well as the object data – a List, but I don’t know how to make this association(List).
class ActivityData
string totalrecords
string pages
List records
I would need to serialize this Activity class to a webget response in json. Similar to this:
[WebGet(ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)]
public Activity GetActivity(string total_records, string sql_params)
{
List<activity> activityList;
using (ModelEntities context = new ModelEntities())
{
resultList = context.CallSP();
}
ActivityData data = new ActivityData();
data.totalrecords = 10;
data.pages = 5;
activity.records = List<activity>;
return activity;
}
You have Few problems:
Both your
ActivityandAcitivityDatamust be mapped entities (that usually mean they must be either tables or views in database) and you must use Linq if you want to load activities and their data in single database roundtrip.You will also have use serialization attributes to ensure that your relations are serializable to JSON.