2022年5月5日 星期四

entity framework 改為搭配 microsoft.data.sqlclient

nuget 安裝 : Microsoft.Data.SqlClient、ErikEJ.EntityFramework.SqlServer

連線字串加入 TrustServerCertificate=True 避免遇到錯誤訊息 : A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0 - 此憑證鏈結是由不受信任的授權單位發出的
例: Server=xxx; Database=xxx;TrustServerCertificate=True;

繼承 dbcontext 的class加入attribute
[System.Data.Entity.DbConfigurationType(typeof(System.Data.Entity.SqlServer.MicrosoftSqlDbConfiguration))]
public partial class xxxContext : DbContext

沒有留言:

自訂權限驗證機制

// 使用 filter [Route("api/[controller]")] [ApiController] [Authorize] [TypeFilter(typeof(CustomAsyncAuthorizationFilter))] public c...