Base solution for your next web application
Open Closed

Error saving related model data #4163


User avatar
0
jdavis01 created

So I am having a bit of an issue when I try to save related model data. I am adding the phoneBook sample to my current project for demonstration sake and when I try to save a person phone number i get the following error....

INFO  2017-11-10 16:46:16,524 [13   ] ore.Mvc.Internal.ControllerActionInvoker - Executed action wcb.ScratchPad.Web.Areas.App.Controllers.PhoneBookController.AddPhone (wcb.ScratchPad.Web.Mvc) in 437.2537ms
ERROR 2017-11-10 16:46:16,697 [13   ] nostics.DeveloperExceptionPageMiddleware - An unhandled exception has occurred while executing the request
System.InvalidOperationException: The property 'Phones' on entity type 'Person' is being accessed using the 'Reference' method, but is defined in the model as a collection navigation property. Use the 'Collection' method to access collection navigation properties.
   at Microsoft.EntityFrameworkCore.ChangeTracking.NavigationEntry.GetNavigation(InternalEntityEntry internalEntry, String name, Boolean collection)
   at Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry`1.Reference[TProperty](Expression`1 propertyExpression)
   at Abp.EntityFrameworkCore.Repositories.EfCoreRepositoryBase`3.EnsurePropertyLoadedAsync[TProperty](TEntity entity, Expression`1 propertyExpression, CancellationToken cancellationToken)
   at Abp.Domain.Repositories.RepositoryExtensions.<EnsurePropertyLoadedAsync>d__2`3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at wcb.ScratchPad.People.PersonAppService.&lt;AddPhone&gt;d__6.MoveNext()

Not sure why ICollection of Phones in the person entity is not considered a navigation property..

Could be the end of the day has the brain tired..


2 Answer(s)
  • User Avatar
    0
    aaron created
    Support Team

    It is a collection navigation property. Use EnsureCollectionLoadedAsync.

  • User Avatar
    0
    jdavis01 created

    Man I feel dumb.... Thanks for the support..