Comments (5)
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.
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.
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.
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.
Sure, thank you . I usually avoid circular references excluding property from Json serialization.
from automapper.collection.
Related Issues (20)
- Override GenerateEntityFrameworkPrimaryKeyPropertyMaps with EqualityComparison? HOT 2
- How to use Collections with Profile configuration? HOT 5
- When mapping Lists, if the DestinationType is added to a DataContext, automapper fails with an exception HOT 1
- How to use with a .Net 5 Web project and DI HOT 1
- EqualityComparison based on the index of item in collection
- Add support for AutoMapper 11.0.0 HOT 1
- Package version constraint violation with AutoMapper.Collection HOT 1
- Are nested lists supported?
- mapping foreign key
- EquivalentExpressionAddRemoveCollectionMapper should implement IObjectMapperInfo HOT 1
- Could not install on .NETFramework,Version=v4.8 HOT 2
- Support for AutoMapper v12 HOT 2
- Insert Master with details HOT 1
- DI cycles forever when calling AddCollectionMappers() twice HOT 3
- Collections with Automapper 12.0.1 doesn't work HOT 1
- Expression of type '<Type>' cannot be used for parameter of type '<OtherType>' of method 'Void Add(<OtherType>)' (Parameter 'arg0') HOT 3
- Attribute based EqualityComparison HOT 1
- Order of lists is not preserved during updates HOT 1
- Dependency Contraint HOT 1
- AutoMapper 13 support
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from automapper.collection.