Issue in mapping model to entity through MappingExtensions

Posted: August 12, 2019 at 4:28 AM Quote #243585
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?
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Thanks & Regards,
Pankaj Dobariya
-----------------------------------------------
Skype : pankaj_dobariya
Email : [email protected]
Posted: August 13, 2019 at 11:19 AM Quote #244637
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());
This post/answer is useful
2
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Jaber Kibria
Software Engineer | nop-station.com
Expertise in .NET Framework, Algolia, Plugins, Themes, Customization, Upgrade, API
Email: [email protected]
Posted: August 13, 2019 at 11:19 AM Quote #244638
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
This post/answer is useful
1
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Jaber Kibria
Software Engineer | nop-station.com
Expertise in .NET Framework, Algolia, Plugins, Themes, Customization, Upgrade, API
Email: [email protected]
Posted: August 14, 2019 at 2:28 AM Quote #244661
Thanks, mhsjaber.

Your answer is very help full.
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Thanks & Regards,
Pankaj Dobariya
-----------------------------------------------
Skype : pankaj_dobariya
Email : [email protected]
Premium support services
  • Dedicated premium support services provided by core developers are intended for persons who run mission critical websites, work on projects with tight deadlines, or want to get dedicated support.
Professional services
  • Want to open a new store? Want to take your store to the next level? Need a custom extension? We can customize nopCommerce to fit your store perfectly. Request a quote to get started.
eCommerce CONFERENCE 2019
Learn more