Issue in mapping model to entity through MappingExtensions

3 months ago
Hello All,

I am doing this.

public partial class MyModel : BaseNopEntityModel
{
public string Name { get; set; }
public bool Published { get; set; }
}

public partial class MyEntity : BaseEntity
{
public string Name { get; set; }
public bool Published { get; set; }
public bool Deleted { get; set; }
public DateTime CreatedOnUtc { get; set; }
public DateTime UpdatedOnUtc { get; set; }
}


public virtual IActionResult Create(MyModel model, bool continueEditing)
{
var entity = model.ToEntity<MyEntity>();
entity.CreatedOnUtc = DateTime.UtcNow;
entity.UpdatedOnUtc = DateTime.UtcNow;
}

When I am trying to map model to entity through "ToEntity".  I am getting this error.
Unmapped properties:
Deleted
CreatedOnUtc
UpdatedOnUtc

Can any one help me how can I use automap in my plugin?
I have see the Category create for reference and write a same code. I can not understand How can I solve this?
3 months ago
Configure your mapper like this.

CreateMap<MyEntity, MyModel>()
.ForMember(entity => entity.Deleted, options => options.Ignore())
.ForMember(entity => entity.CreatedOnUtc, options => options.Ignore())
.ForMember(entity => entity.UpdatedOnUtc, options => options.Ignore());
3 months ago
You can also follow nopCommerce provided examples from this file.

https://github.com/nopSolutions/nopCommerce/blob/develop/src/Presentation/Nop.Web/Areas/Admin/Infrastructure/Mapper/AdminMapperConfiguration.cs
3 months ago
Thanks, mhsjaber.

Your answer is very help full.