On update related entities' properties are all null - using EF code first

2 posts, 0 answers
  1. Johan
    Johan avatar
    19 posts
    Member since:
    Aug 2010

    Posted 17 Sep 2013 Link to this post

    Hi

    Using ajax my data source is configured as follow:

    .Read(read => read.Action("Containers_Read", "ContainerAdmin"))
            .Create(update => update.Action("Containers_Create", "ContainerAdmin"))
            .Update(update => update.Action("Containers_Update", "ContainerAdmin"))
            .Destroy(update => update.Action("Containers_Delete", "ContainerAdmin"))
    When my grid first loads all the related entities with data comes through from the repository just fine:

    public ActionResult Containers_Read([DataSourceRequest] DataSourceRequest request)
            {  
                return Json(_repository.GetAllAssetTakeOnContainers().ToDataSourceResult(request));
            }
    public List<AssetTakeOnContainer> GetAllAssetTakeOnContainers()
            {
                using (var context = new AssetTakeOnContext())
                {
                    context.Configuration.LazyLoadingEnabled = false;
     
                    return context.AssetTakeOnContainers.Include("TakeOns").Include("LocationLevel1").Include("LocationLevel2").Include("LocationLevel3").Include("CostCntrLevel1").Include("CostCntrLevel2").Include("CostCntrLevel3").Include("Contact").Include("RoomType").Where(c => c.IsDeleted == false).ToList();
                }
            }
    But as soon as I do an update my related entities seems to be populated but all properties set to null:

    [AcceptVerbs(HttpVerbs.Post)]
            public ActionResult Containers_Update([DataSourceRequest] DataSourceRequest request, AssetTakeOnContainer container)
            {
                _repository.UpdateAssetTakeOnContainer(container);
     
                return Json(ModelState.ToDataSourceResult());
            }
    Please see attached file for a screenshot from VS.

    Can someone please tell me why this is and what I'm doing wrong here?

    Thanks
  2. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2192 posts

    Posted 19 Sep 2013 Link to this post

    Hi Ryno,

    I tried to reproduce the problem locally but to no avail – everything is working as expected on our side. Could you please provide runable project where the issue is reproduced? This would help us pinpoint the exact reason for this behavior.

    Also please note that our offline demos contains such example of editing of nested properties -  "Editing custom". The offline examples can be found under the installation folder of KendoUI:

    • ..\Telerik\Kendo UI for ASP.NET MVC Q2 2013\wrappers\aspnetmvc\Examples
    Kind Regards,
    Vladimir Iliev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top