###### tags: `Asp.net Core`, `EF` # Asp.net core5 EF建立專案 範例為今日要製作一個 <font color=#FF6600>Device</font> 的 CRUD API ### 先建立DeviceController.cs ### 在Startup.cs加入程式進入點 ``` csharp=1 public void ConfigureServices(IServiceCollection services) { // 連線mairadb services.AddDbContext<ApplicationDBContext>(options => options.UseMySql(Configuration.GetConnectionString("DefaultConnection"), new MariaDbServerVersion(new Version(10, 6, 4)))); // 注入DI告知程式進入點 services.AddScoped<IDeviceRepository, DeviceRepository>(); services.AddAutoMapper(typeof(DeviceMappers)); } ``` ### 使用EF建立資料庫 (套件管理器主控台) 1. 初始化資料庫 語法: ``` csharp=1 Add-Migration xDevice ``` 2. 更新資料庫 語法: ``` csharp=1 update-database ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up