Giter Site home page Giter Site logo

Comments (5)

TylerCarlson1 avatar TylerCarlson1 commented on June 25, 2024

It should as long as your CreateMap is called in the MyMapperProfile. I honestly haven't tried the BuildExecutionPlan to see if it's in sync or not. Also I'm not 100% sure when you map a class to itself it will mess up the equality logic or not. AutoMapper doesn't allow that by default and it's more of a hack in this instance.

Another thing could be that services.AddAutoMapper could have an issue with registering it. I'm not super familiar with how that works.

from automapper.collection.

TylerCarlson1 avatar TylerCarlson1 commented on June 25, 2024

Oh I might know what the issue might be. You have to set EnabledGroups to a value on constructor or parameter initialization.

public class UserProfile : IdentityUser<long>, IDomainEntity
    {
        public virtual List<GroupPerUser> EnabledGroups { get; set; } = new HashSet<GroupPerUser>();
    }

This should fix the updating problems in Entity Framework

from automapper.collection.

ste4net avatar ste4net commented on June 25, 2024

Thank you very much.
I use often this approach when i have simple entity avoiding to create child DTO.
But... sorry it was not an Autmapper issue i have been messed up by the fact that it was happening only using mapping function but going a little bit deeper i saw that it was not Automapper deleting items it was EfCore calling dbCtx.Entry(tmpEnt)
It was a stupid things related to USerProfile property of GroupPerUser.
Source was null and obviously Automapper set null to destination than EFCore seeing that the property has been changed to null treat it like a removed entity and remove it from collection .
Simply solved asking Automapper to ignore that property
CreateMap<GroupPerUser, GroupPerUser>() .EqualityComparison((g1, g2) => g1.UserProfileId == g2.UserProfileId && g1.GroupId == g2.GroupId).ForMember(g => g.UserProfile, m => m.Ignore());

Thank you for your help.

from automapper.collection.

TylerCarlson1 avatar TylerCarlson1 commented on June 25, 2024

For your DTO's it's recommended not to have circular references, because it causes things like that. Also causes issues with projection and setting a max depth to stop the circular reference.

Best would be to make a new GroupPerUserVM and not include UserProfile property and that should cause the least amount of problems going forward.

from automapper.collection.

ste4net avatar ste4net commented on June 25, 2024

Sure, thank you . I usually avoid circular references excluding property from Json serialization.

from automapper.collection.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.