Questions tagged [mapster]

Mapster is an open source object mapper for .NET,

Mapster is an open source object mapper for .NET.

https://github.com/eswann/Mapster

114 questions
0
votes
0 answers

Mapster ProjectToType breaks when using GroupBy/Select

I use Mapster Mapper to project from domain models to DTOs. That works perfectly, but now I had to use a GroupBy/Select and that breaks my code: public class Document { [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Guid Id {…
Mads
  • 385
  • 1
  • 5
  • 18
0
votes
0 answers

Reversemap with Mapster, using TypeAdapterConfig.GlobalSettings.Default.NameMatchingStrategy

I'm using following code to map my classes, and it is working perfectly in one direction, but I want to use same approach to automatically use TwoWays (reverse) mapping, but that is not working using second portion of code: static string…
0
votes
0 answers

Can MapsterMapper/Mapster map an Expression tree just like AutoMapper do?

MapsterMapper/Mapster 7.3.0 EFCore 7.0.5 asp.net core 7.0.0 I have two generic type in my BuzService class, one is TModel and other one is TEntity. TModel is a DTO class, TEntity is an entity class. I have a method in the service class public…
0
votes
1 answer

Map request object and add extra string to destination object using mapster

I am trying to Map a request object plus and extra string to another object using C# Mapster. However I cant seem to find a solution to do it. The user sends a request and the controller recieves a object from this class public record…
Martin Rohwedder
  • 1,712
  • 4
  • 19
  • 34
0
votes
0 answers

Can MapsterMapper/Mapster automatic updates DTO when entity changed?

MapsterMapper/Mapster MapsterMapper/Mapster 7.3.0 EFCore 7.0.5 asp.net core 7.0.0 Entity Class public class Setting { [Key] public Guid Id {get;set;} public string Name {get;set;} public string Value {get;set;} } Dto…
0
votes
1 answer

Mapster Not Mapping Nested Collections Correctly in .NET 7

I am having an issue with mapping nested collections using Mapster in .NET 7. The mapping seems to fail for the second-level collection (Bs inside A). This is surprising because, during debugging, I can see that A does have Bs with Cs. Here are my…
0
votes
1 answer

Mapster not mapping derived class in a List c#

I have multiple classes implementing a base class, e.g.: public abstract class Step { public StepId Id {get; set;} public string Text {get; set; public StepType Type {get;set;} } public class SelectionStep : Step { public…
Febre
  • 68
  • 4
0
votes
0 answers

search a string between property values after mapping to an object using mapster and before executing query

how can I apply predicates after projecting to a type with mapster? so I have this public sealed class PRGeneric : where T : class { public async Task> GetPaginated( Expression>? OrderField, bool…
0
votes
0 answers

Mapster: excluding records according to their value?

Bottom line, after reviewing comments: Not possible with Mapster, and it's not Mapster's "mandate" - it belongs to business logic (before/after mapping). Original question: Is there a way to exclude/ignore records/entries according to their…
Tar
  • 8,529
  • 9
  • 56
  • 127
0
votes
1 answer

Mapster thinks my property access in lambda is not property access

I have two way config for mapping using Mapster: public static TwoWaysTypeAdapterSetter ClientConfig => TypeAdapterConfig .NewConfig() .TwoWays() .Map(dest…
Szyszka947
  • 473
  • 2
  • 5
  • 21
0
votes
0 answers

C# Mapster error when trying to map IEnumerable where T requires DI Service

I have the following class: public class FooDto { public string Secret { get; set; } } I have configured the mapping as follows: config.NewConfig() Map(dest => dest.Secret, src =>…
0
votes
1 answer

Mapping Dictionary to object instance of some type excluding property names not present in the dictionary using Mapster

Decided to use Mapster instead of writing my own conversion/mapping methods. Haven't found anything that would suffice my use case on their github wiki. I have an instance of Dictionary where keys are property names of target type…
0
votes
1 answer

Mapster - How to map parent property to a list

I have a class with a property that is a list of child class. I'm trying to map the Id of the parent class to a property in each item of the list. Example (c#): // Source. public class Person { public string Id { get; init; } public string…
0
votes
0 answers

Mapster mapping collection to id references

I'd like to create a dto that has a collection of reference id's to the object that is stored in a collection in the entity. As illustrated below: public class MainEntity{ public int Id {get;set;} public ICollection Others…
dgo
  • 3,877
  • 5
  • 34
  • 47
0
votes
1 answer

How do I use reflection to create a mapping between multiple libraries with identical models C#?

I have three libraries, each containing a namespace for models, and all the models in each library are effectively identical in the data they hold--they have minor differences in how they are implemented, but I don't have control over that as the…