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
7
votes
2 answers

Mapster Global Configuration with Dependency Injection

I'd like to know if there is a way to globally configure Mapster while using Dependency Injection? The configuration options appear to be for the static usage and also for a singleton pattern only. Mapster Configuration Mapster Dependency…
Fosol
  • 137
  • 1
  • 6
6
votes
1 answer

How to map inherited class using Mapster

I would like to map between two classes by using the following statements: var directoryDataModel = new DirectoryDM() { Title = "School Directory", Persons = new List() { new TeacherDM() { Name = "Johnson", Department =…
Brian Rice
  • 3,107
  • 1
  • 35
  • 53
5
votes
1 answer

How to get class library assembly reference in .NET Core project?

I have an ASP.NET Core project (netcoreapp2.0) that references models in a class library project (netstandard2.0). I'm trying to use Mapster to map objects stored in the class library. The documentation for Mapster says to call the Scan method from…
Jason
  • 2,455
  • 4
  • 37
  • 48
4
votes
4 answers

How to create a reusable mapping profile with Mapster?

I have a .Net 5 Web Api project and want to use Mapster v7.2.0 to avoid mapping objects manually. The following code shows a sample scenario setup a mapping configuration map from multiple sources map to fields with different…
Question3r
  • 2,166
  • 19
  • 100
  • 200
4
votes
1 answer

Mapster.Tool use codegen to generate mappers but not DTOs

Can I use Mapster.Tool to generate Mappers without also generating the class that I'm mapping to? I have a typical Domain objects to and from DTOs scenario but the sample code…
Christopher Edwards
  • 6,589
  • 8
  • 43
  • 57
3
votes
1 answer

Mapster: Mapping Properties of different types, No default constructor for type 'CultureInfo', please use 'ConstructUsing' or 'MapWith'

I use Mapster with version 7.3.0 and .Net 7.0.1 I have two classes. public class Entity { public Guid Id { get; set; } public string Content { get; set; } = default!; public string Note { get; set; } = default!; public CultureInfo…
coolboy
  • 33
  • 4
3
votes
1 answer

Mapster how to inject configuration object into type configuration

I want to inject configuration object into Mapster. Below is the code. public class DownloadLinkMappingConfig : IRegister { private readonly IConfiguration Configuration; public DownloadLinkMappingConfig(IConfiguration…
M. Ko
  • 563
  • 6
  • 31
3
votes
0 answers

Mapster ignore mapping in a list

If I have a parent object with a list of child objects, and these child objects have a boolean telling should they be included in the mapping, how can I do this filtering in Mapster? Code example: class Parent { public List Children…
hablahat
  • 182
  • 1
  • 8
3
votes
0 answers

Mapster: map to an interface with both readonly and writeable properties?

We've run into an issue mapping a class to an interface using Mapster 7.2.0. Mapping to target interface public interface ITarget { int GetOnlyProperty {get;} int GetSetProperty {get;set;} } with source.Adapt() always results in…
AunAun
  • 1,423
  • 2
  • 14
  • 25
3
votes
1 answer

Mapster and Blazor

I would like to plug and use Mapster in my Blazor project. I can't find a good reference on how to register mappings and get them injected in the different layers of my application. Does anyone know how do I achieve that? Thank you
ab_732
  • 3,639
  • 6
  • 45
  • 61
3
votes
0 answers

CodeGen creates empty mapper file on the first build

When I decorate my domain class with [AdaptTo("[name]Dto"), GenerateMapper] everything works fine, but when I use: public class MappingRegister : ICodeGenerationRegister { public void Register(CodeGenerationConfig config) { …
Nafas
  • 183
  • 1
  • 9
3
votes
1 answer

Adapt navigational property using Mapster

I have a Post class with a User property in it. When I try to get all Posts, I also want to map the User to a UserDto object. public class Post { public Guid Id {get; set;} public string Content {get;set;} public User User {get;…
blankface
  • 5,757
  • 19
  • 67
  • 114
3
votes
1 answer

Get Empty Collection instead of null when mapping with Mapster

We have an huge data driven application that involves multiple systems therefore a lot of mapping is needed. Due to performance issues we are gonna migrate from AutoMapper to Mapster. Everything's good so far with Mapster but when mapping the…
Hannan Ayub
  • 378
  • 2
  • 15
3
votes
1 answer

How do I Mapster Ignore Id values when sourcetype has Dto in the type name

I've read this page, but it didn't have the answer. https://github.com/MapsterMapper/Mapster/wiki/Ignoring-members What I want is to ignore all Id fields when the Source type is named like SomethingDto or FooDto Something like…
redwards510
  • 1,802
  • 1
  • 17
  • 23
3
votes
1 answer

Mapster - How to do ignore mapping for null properties

I'm using Mapster to map Dto instances to Model objects. The Dtos are sent by a Javascript client, sending only the properties updated. I would like to ignore null values, and have Mapster leave the model instance unchanged for this properties. A…
Alberto Chiesa
  • 7,022
  • 2
  • 26
  • 53
1
2 3 4 5 6 7 8