-
- add Package "AutoMapper"
- add Package "AutoMapper.Extensions.Microsoft.DependencyInjection"
- create "MappingConfig"
using AutoMapper; public class MappingConfig : Profile { public MappingConfig() { CreateMap<TFrom, TTo>() // to create map From TTo to TFrom .ReverseMap(); } }
- in
Program.cs
builder.Services.AddAutoMapper(typeof(MappingConfig)); //before add controller builder.Services.AddControllers();
- To Use
- in
Controller
IMapper _mapper {get;} public Controller(IMapper mapper) { _mapper = mapper; } public ActionResult<List<DataDto>> GetData() { List<Data> list = _dataRepository.Get(); return Ok(_mapper.Map<List<DataDto>>(list)) } public ActionResult<DataDto> GetDataItem(int id) { Data item = _dataRepository.Get(id); return Ok(_mapper.Map<DataDto>(item)) }
- in
-
Using Terminal
- create migration
dotnet ef migrations add MigrationTitle --project ProjectName
- remove migration
dotnet ef migrations remove
- apply migration
dotnet ef database update
- create migration
-
Using Package Manager Host
- create migration
#if only one dbcontext Add-Migration MigrationTitle #if multiple dbcontext Add-Migration MigrationTitle --Context YourDBContextClassName #to remove migration Remove-Migration
- remove migration
#if only one dbcontext Remove-Migration #if multiple dbcontext Remove-Migration --Context YourDBContextClassName
- apply migration
Update-Database #if multiple dbcontext Update-Database --Context YourDBContextClassName
- create migration
-
show running
ps
-
kill running project
kill -9 $(lsof -i:PORT -t) 2> /dev/null #e.g #my local api kill -9 $(lsof -i:7069 -t) 2> /dev/null #or #my local blazor server kill -9 $(lsof -i:7070 -t) 2> /dev/null
-
dotnet build /Users/macbookpro/Documents/Projects/Reference/WebApp/TestASP/TestASP.sln /property:GenerateFullPaths=true
-
dotnet build /Users/macbookpro/Documents/Projects/Reference/WebApp/TestASP/TestASP.API/TestASP.API.csproj /property:GenerateFullPaths=true
-
{ "version": "2.0.0", "tasks": [ { "label": "build", "command": "dotnet", "type": "process", "args": [ "build", "${workspaceFolder}/TestASP.sln", "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary;ForceNoAlign" ], "problemMatcher": "$msCompile" }, { "label": "publish", "command": "dotnet", "type": "process", "args": [ "publish", "${workspaceFolder}/TestASP.sln", "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary;ForceNoAlign" ], "problemMatcher": "$msCompile" }, { "label": "watch", "command": "dotnet", "type": "process", "args": [ "watch", "run", "--project", "${workspaceFolder}/TestASP.sln" ], "problemMatcher": "$msCompile" } ] }```
-
{ "version": "2.0.0", "tasks": [ { "label": "build", "command": "dotnet", "type": "process", "args": [ "build", "${workspaceFolder}/TestASP.sln", "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary;ForceNoAlign" ], "problemMatcher": "$msCompile" }, { "label": "publish", "command": "dotnet", "type": "process", "args": [ "publish", "${workspaceFolder}/TestASP.sln", "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary;ForceNoAlign" ], "problemMatcher": "$msCompile" }, { "label": "watch", "command": "dotnet", "type": "process", "args": [ "watch", "run", "--project", "${workspaceFolder}/TestASP.sln" ], "problemMatcher": "$msCompile" } ] }