Issue in mapping model to entity through MappingExtensions

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
4 Jahre weitere
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?
4 Jahre weitere
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());
4 Jahre weitere
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
4 Jahre weitere
Thanks, mhsjaber.

Your answer is very help full.
3 Jahre weitere
mhsjaber wrote:
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());



It was a  great help  after wasting 2 3 hours .thanks
3 Jahre weitere
mhsjaber wrote:
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());


Hello, I do the same in my project but with other property and getting error AutoMapper.AutoMapperMappingException: 'Missing type map configuration or unsupported mapping.'

my entity have only one string and int, like in model and getting this error all the time.
I take configuration from Nop.web/admin/infrastructure/mapper and put it in nop.web/infrastructure because i dont need it in admin panel and now i get same error all the time.
is there any way to fix this error.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.