On Feb 21, 2019, I uploaded my first Mapper NuGet on "www.nuget.org". You can find it
here, which helps the developers to map object properties from one to another without adding any complex lines.
For example, if we have one entity table which has 30 or more than 30 properties and we want to use it in all properties with ViewModel, we have to write the same line 30 times like below.
- viewModel.Col1 =entityObj.Col1;
- viewModel.Col2 =entityObj.Col2;
- viewModel.Col3 =entityObj.Col3;
- …
This is definitely time-consuming and increases the number of lines. It is also possible to mismatch the properties which will result in an error. So, to overcome this kind of thing, I uploaded the Nuget which you can install using the below methods.
Using Package Manager
- Install-Package Faisal.Map.Object -Version 1.0.4
Using .NET CLI
- dotnet add package Faisal.Map.Object --version 1.0.4
Using Paket CLI
- paket add Faisal.Map.Object --version 1.0.4
Using NuGet - Solution
I also published an article about Generic Extension method which you can read
here. This article explains only mapping for the single class/object. In NuGet, I added to map List<class> too.
How to use (After install NuGet),
To Map Single Object.
- Students student = _dbContext.Students.Where(a=>a.ID == 1);
- StudentsViewModel records = student.MapProperties<Students>();
To Map List of Object.
- List<StudentsViewModel> studentsVM = new List<StudentsViewModel>();
- List<Students> students = _dbContext.Students.ToList();
- students.MapListProperties<Students, StudentsViewModel>(studentsVM);
I hope this NuGet will be helpful and useful in your project. Please install it and give your valuable feedback and comments. Let me know how you like and understand this blog and how I could improve it.