I need to extend my model with a one-to-many realtion, how do I do that?

4 posts, 1 answers
  1. Jonas
    Jonas avatar
    42 posts
    Member since:
    Oct 2014

    Posted 03 Sep 2015 Link to this post

    Hello

    I have a grid displaying workitems and the last action taken for a workitem, recently I discovered that I need to extend this to include a history of actions stored in a separate table in the db.

    the two tables looks like this:

    workItem
    id
    name
    lastActionDate
    lastActionText

    workAction
    id
    workItemID
    actionDate
    ActionText

    My model currently looks like this:

    public class workItemModel
        {
            public int id { get; set; }
            public string name{ get; set; }
            public DateTime lastActionDate{ get; set; }
            public string lastActionText{ get; set; }
        }

    and my read action for the grid looks like this:

    public ActionResult workItems_Read([DataSourceRequest]DataSourceRequest request)
            {
                return Json(GetWorkItems().ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
            }
     
            private static IEnumerable<workItemModel> GetWorkItems()
            {
                var wimDB = new wimDB_DEVEntities();
                return wimDB.workItem.Select(wiModel => new workItemModel
                {
                    id = wiModel.id,
                    name = wiModel.name,
                    lastActionDate = wiModel.lastActionDate,
                    lastActionText= wiModel.lastActionText
                });
            }
     

    How do I extent my model and my read action to include the workAction table from the db?

    /Jonas

  2. Jonas
    Jonas avatar
    42 posts
    Member since:
    Oct 2014

    Posted 04 Sep 2015 in reply to Jonas Link to this post

    Hello

    No one got an answer for this?

    /Jonas

  3. Answer
    Viktor Tachev
    Admin
    Viktor Tachev avatar
    2291 posts

    Posted 04 Sep 2015 Link to this post

    Hi Jonas,

    Please check out the following article that describes how you can configure more complex Model.




    Regards,
    Viktor Tachev
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  4. Jonas
    Jonas avatar
    42 posts
    Member since:
    Oct 2014

    Posted 08 Sep 2015 in reply to Viktor Tachev Link to this post

    Thank you!
Back to Top