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
1
vote
0 answers

Mapster - TypeLoadException

I'm trying to use Mapster to map an object from CcmApplication to RpcCcmApplication and getting the following exception: TypeLoadException: Signature of the body and declaration in a method implementation do not match. Type: 'GeneratedType_1'. …
cogumel0
  • 2,430
  • 5
  • 29
  • 45
1
vote
1 answer

How to map Id property to ClassId with Mapster?

I have a 'database' class named User: class SqlUser { public int Id {get;set;} } and a DTO for it: class User { public int UserId {get;set;} } Is there a way to map this automatically using Mapster? It does not work by default. If it does require…
Dmitry Arestov
  • 1,427
  • 12
  • 24
1
vote
1 answer

C# Mapster with explicit overload assignement

Mapster seems to not know how to map a simple assignment UPDATE 1: I added a method Value() to get the value of the Guid, if instead of a method I use a property public Guid Value => _value the mapping works. I have an Id class public class Id { …
dariogriffo
  • 4,148
  • 3
  • 17
  • 34
1
vote
0 answers

Adding custom logics to Mapster's mapping, possibly with AfterMapping?

The Question After mapping Input to Output, the returned Input must have an incrementing number in its Entries[i].Id, (i.e. Entries[0].Id = 1, Entries[1].Id = 2, Entries[2].Id = 3, ...). So I tried to put it in AfterMapping: [Mapper] public…
Tar
  • 8,529
  • 9
  • 56
  • 127
1
vote
0 answers

Can Mapster work with readonly collections?

I wanted to use Mapster to map some classes. My origin class is this: public partial class Componente : ObservableObject { public Componente() { } public Componente(long paramLgId) : base() { this.Id =…
Álvaro García
  • 18,114
  • 30
  • 102
  • 193
1
vote
0 answers

Custom Value Resolver in Mapster

I've been working with AutoMapper and it was quite joyful but for a number of reasons I got to use Mapster in my new project. As you may know we had a handy configuration for CustomValueResolvers: CreateMap
Ali.Rashidi
  • 1,284
  • 4
  • 22
  • 51
1
vote
0 answers

How to map multiple entities to one class in Mapster

In AutoMapper, we can map multiple entities to one, but can't impl in mapster. Automapper demo code: Entity: var users = await _userManager.Users .AsNoTracking() .ProjectTo(new { roles = _roleManager.Roles }) …
Binbin
  • 11
  • 2
1
vote
1 answer

Mapster how to inject DB context into mapping config

I need to use the DB context to map a nested object based on the Name property which is a string. I'm trying to inject DB context into the Mapping Config but I get the following error: System.MissingMethodException: Cannot dynamically create an…
Guillermo Verón
  • 218
  • 1
  • 11
1
vote
1 answer

Get mapping expression with Mapster

Is it possible to get just the mapping expression, i.e., an object of type System.Linq.Expressions.Expression>? I would like to manually pass it to a Select-like function accepting an expression.
gius
  • 9,289
  • 3
  • 33
  • 62
1
vote
0 answers

Mapster: how to instantiate an interface field with a specific implemetation?

For example I have ObjectA: public class ObjectA { public int ID { get; set; } public UserInfo UserInfo { get; set; } } and ObjectB: public class ObjectB { public int ID { get; set; } public IDataUserInfo UserInfo { get; set; } } I…
1
vote
0 answers

Update an existing object and ignore members based on member value using Mapster Mapping tool

I use Mapster package for mapping two objects. An existing object is updated (patched) by applying some rules in the source object and ignore some properties based on their values and Property Type using a function. I try to use the method…
M.Hassan
  • 10,282
  • 5
  • 65
  • 84
1
vote
0 answers

How to map DataTable using MapsterMapper?

I am trying to map a DataTable to a dto DataTable but facing the error. I am using CQRS and MediatR. Here is my code. I gave a basic implementation here. Controller.cs [Route("api/[controller]")] [ApiController] public class MapDataTableDemo :…
Aman
  • 13
  • 3
1
vote
1 answer

specifying assembly in layered architecture

I specify mapster service operations in web program.cs in layered architecture, but I want to use this application in another layer. And I'm having trouble choosing assembly. Web Layer Program.cs var config =…
Berk KARASU
  • 71
  • 1
  • 9
1
vote
0 answers

Mapping nullable strings with Mapster

I'm wondering if anyone has ran into this before. I have a simple mapping below to convert between a string and Email. public void Register(TypeAdapterConfig config) { config.NewConfig() .MapWith(value =>…
Paul DeVito
  • 1,542
  • 3
  • 15
  • 38
1
vote
0 answers

Recursive Mapster Mapping For Factory on `MapWith` and `ConstructUsing`

I have an entity that looks like this: public class Author : BaseEntity { public virtual string Name { get; private set; } public virtual Address PhysicalAddress { get; private set; } [JsonIgnore] [IgnoreDataMember] …
Paul DeVito
  • 1,542
  • 3
  • 15
  • 38