2022年5月14日 星期六

madvr + HDR 影片變灰

madvr 設定問題,參考如下 






就算螢幕實際只有8bit,但還是要選 auto,不能用預設的8bit,否則就會有問題

2022年5月5日 星期四

dll 專案使用內建連線字串

不要依賴組態設定檔,因為參考的專案不會使用到,直接於程式內處理
雖然可以在參考專案的組態設定檔加入相同設定,但缺乏獨立性且麻煩,也會造成 .net 6.0 專案無法使用 .net 4.8 的dll,因為組態設定檔架構不同

1. 擴充 DbContext class,設定連線字串,並提供產生物件的函數
 public partial class xxx : System.Data.Entity.DbContext
    {
        static string ConnectionString = "metadata=xxx;provider=System.Data.SqlClient;provider connection string=\"xxx\"";
        private xxx(string connectionString)
       : base(connectionString)
        {
        }

        public static xxx CreateDbContext()
        {            
            return new xxx(ConnectionString);
        }
    }

2. 使用連線物件
using (var db = xxx.CreateDbContext()) {
}

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

Entity Framework 建立新物件並儲存後馬上取得關聯資料

使用 CreateProxy 建立物件,不要直接 new var newmodel = _contextXXX.CreateProxy<yyy>(); ... _contextXXX.yyy.Add(newmodel); await _contextXXX.SaveC...