Having some problems with this. It seems that the original design was easy to use, but there are so many ways to implement this in a new design without a static Api. I do not find a single method that would be clear. Many videos and tutorials started to end, but with code syntax that I just don't know.
I just started creating a new application and I want to implement it from the very beginning, if possible.
Can someone give a detailed example of how to implement this from scratch with the next starting point? I understand that the example is so simple that it doesn’t need an automapper
Using MVC w / Code First and EF
Model example
public class Person
{
public int id { get; set; }
public string name { get; set; }
public DateTime created { get;set;
}
ViewModel Example
public class User
{
public string name { get; set; }
}
Controller example - (bit coarse :))
using AutoMapper;
......
[HttpPost]
public ActionResult AddUser(User user)
{
Person person = new Person();
person.name = user.name;
person.created = DateTime.Now;
db.Persons.Add(person);
db.SaveChanges();
return RedirectToAction("Index");
}
I just want to display the name field in this example from ViewModel to Model.
, , .
> https://github.com/AutoMapper/AutoMapper/wiki/Getting-started
? ,
?
Mapper.Initialize(cfg => cfg.CreateMap<Order, OrderDto>());
Mapper.Initialize(cfg => cfg.CreateMap<User, Person>()); // this is what i did in the controller and Global.asax which isnt valid
Action?
"" ""?
OrderDto dto = Mapper.Map<OrderDto>(order);
" AutoMapper"
- Global.asax , "anyIWant", ? , ( ) Global.asax "Application_Start()"?
? ? .. . ...
> https://www.youtube.com/watch?v=-5sZ7hq3J10 2:46, , . , , , .
, , , !
, ...
: . , ? , . "" , , . github .
-ActionResult :
var person = Mapper.Map<Person>(user);
EDIT: " ".
Global.asax "Application_Start()", . :
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
MappingConfig.RegisterMaps(); // Right here
}
, , ? , , , , .