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
1 answer

Configure globally property types mapping for all models using Mapster

I have a LocalizedString struct with a GetCurrentLocalization() method and I want to call it when map an Entity to a DTO (so I don't have to do it manually). And ideally, do not manually configure mappings every time, but write a global config once…
jurilents
  • 159
  • 1
  • 1
  • 10
1
vote
1 answer

When we use OData and Mapster in EF Core with customDTO. OdataQueryOptions is getting overridden

What we want to do is that the tenant attached to the carrier does not come under all circumstances. I have OData and Mapster in my .NET Core project. I want to convert the OData query to dto with ProjectToType, which I also use in mapster. However,…
1
vote
1 answer

How can to map to a wrapper class using Mapster?

Based on my project I need to create a wrapper for “IFormFile”, Actually I created a “AppFileProxy” class and “IAppFile” interface for this purpose : IAppFile.cs : public interface IAppFile { string Name { get; } string FileName { get; } …
Mohsen Saniee
  • 204
  • 2
  • 17
1
vote
1 answer

Automapper / Mapster C# - how do I map collection from specific property?

It is weird but I am stuck with a pretty simple case: Say I have a class: class Record { public List Data {get; set;} public string OtherProp1 {get; set;} public string OtherProp2 {get; set;} } And I want to map a List
Alexander
  • 49
  • 1
  • 7
1
vote
0 answers

How to use Mapster to do type level mapping, with special mapping logic?

public static void Initialize() { TypeAdapterConfig.NewConfig() .MapWith(s => Convert(s)); } private static DateTime? Convert(string? s) => DateTime.TryParseExact( s,…
Nico
  • 497
  • 1
  • 4
  • 15
1
vote
1 answer

Mapster Adapt from dynamic type to class

I have to manage a lot of API calls to a service and all the response messages have a common structure except the "data" field which varies according to the endpoint called and whether the call was successful or not. Looking for a way to smartly…
1
vote
0 answers

Mapster ConstructUsing with class with multiple ctor problem (bug?)

I have a problem with Mapster. There is some classes public class DtoClass { public string Name { get; set; } public ParamValueDto Value { get; set; } } public class ParamValueDto { public int Value { get; set; } } public class…
srvr4vr
  • 173
  • 1
  • 9
1
vote
1 answer

Mapster not mapping

I'm using Mapster with DI and I'm trying to map objects that I receive from WS. I was following this guide https://github.com/MapsterMapper/Mapster/wiki/Dependency-Injection#mapping I register TypeAdapterConfig, and ServiceMapper var config = new…
1
vote
2 answers

Mapster map using multiple objects to one

I am using mapster and C# in visual studio and have three objects I need to map to one. Has anyone done this, any examples? Mapster says it has that capability but I can't get it to work. Thanks.
jaykum
  • 138
  • 3
  • 10
1
vote
0 answers

How to write a config to source generate a mapper for IReadOnlyCollection using Mapster?

How can I write a config to source generate a mapper from IReadOnlyCollection to IReadOnlyCollection using Mapster? I have tried doing the following but it does not work. public class MapsterConfiguration : IRegister { public void…
1
vote
1 answer

How to map JsonPatchDocument using Mapster?

I have my model: public class Membership { [Key] [Required] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Id { get; set; } [Required] [MinLength(3)] [MaxLength(30)] public string Name { get; set;…
1
vote
2 answers

How to map self-reference with Mapster?

I have list with items contained self reference. For example: Model public class Stock{ public int StockId { get; set; } public int? ParentStockId { get; set; } public int Level { get; set; } public string Name { get; set; } } ViewModel …
1
vote
1 answer

Using Mapster to map from flat model to a model with nested properties in TypeAdapterConfig

Using EF Core 3 and Mapster I would like to map from a flat dto object to an object with a related sub-object. i.e. _ = TypeAdapterConfig.NewConfig() .Map(d => d.Detail, s => s.Description) .Map(d => d.Id, s =>…
John S
  • 7,909
  • 21
  • 77
  • 145
1
vote
1 answer

Updating the key between an entity and a list of sub-entities?

I am using EF6 and Mapster in an ASP.Net MVC project. In my Edit post controller I am trying to save the results of a data entry form. On the form there is a multiselect list box. The selections in the multiselect list box are getting passed along…
John S
  • 7,909
  • 21
  • 77
  • 145
1
vote
1 answer

Disable "getPropertyName" method mapping to property for mapster

Suppose I have two classes and use Mapster to map one to another: class A { public int GetX(){ return 1; } } class B { public int X { get; set; } } Is any way to globally disable map of GetX() to X for A to B mapping? This behavior is by…
FLCL
  • 2,445
  • 2
  • 24
  • 45