Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Arjan H. 221 posts 457 karma points c-trib
    Jan 23, 2023 @ 13:58
    Arjan H.
    0

    SaveImpl() on custom repository doesn't work

    I'm using a custom KonstruktRepository, but the protected override T SaveImpl(T entity) doesn't seem to be working. When I save an entity the custom SaveImpl() method is never hit and I get the following error:

    Sequence contains more than one matching element

    at System.Linq.ThrowHelper.ThrowMoreThanOneMatchException()
       at System.Linq.Enumerable.TryGetSingle[TSource](IEnumerable`1 source, Func`2 predicate, Boolean& found)
       at Konstrukt.Web.WebApi.Validation.KonstruktEntityValidator.ValidatePropertyData(ModelStateDictionary modelState, KonstruktEntityPostModel postModel, KonstruktEditorFieldConfig[] configProps, Object entity, KonstruktEditorMode editorMode)
       at Konstrukt.Web.WebApi.Validation.KonstruktEntityValidator.Validate(KonstruktCollectionConfig collectionConfig, ModelStateDictionary modelState, KonstruktEntityPostModel postModel, Object entity, KonstruktEditorMode editorMode)
       at Konstrukt.Web.Controllers.Api.KonstruktApiController.SaveEntity(KonstruktEntityPostModel postModel)
       at lambda_method201(Closure , Object , Object[] )
       at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
       at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
       at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
       at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()
    --- End of stack trace from previous location ---
       at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
       at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
       at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
    --- End of stack trace from previous location ---
       at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|26_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
    

    Or am I missing something?

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Jan 23, 2023 @ 14:09
    Matt Brailsford
    100

    So it's failing property validation before it event gets to your entity save routine.

    Looking at the code for ValidatePropertyData it would appear it fails when it tries to lookup a configured property in your post model. The ThrowMoreThanOneMatchException would suggest you somehow have more than one property that matches a specific alias.

    I'd check your config / models for duplicate properties.

  • Arjan H. 221 posts 457 karma points c-trib
    Jan 23, 2023 @ 14:30
    Arjan H.
    0

    I wanted to an "Info label" data type to the top of the editor view which shows some basic instructions. I had to bind it to an entity field in the AddField() method, so I used the Name field, but this field was also being used in another editor field. I've now added a dummy/placeholder field to the entity model that I can use to display the info label:

    enter image description here

    And now the SaveImpl() method works as expected.

Please Sign in or register to post replies

Write your reply to:

Draft