2023年1月6日 星期五

bootstrap5 學習心得

toast 用法

html
====
<div class="toast-container position-fixed top-0 end-0 p-3">
<div id="toast1" class="toast hide text-white bg-success ">                
<div class="toast-body">
{{toast訊息}}
</div>
</div>
        <div id="toast2" class="toast hide text-white bg-danger " data-bs-autohide="false">
                <div class="toast-body">
                    {{toast訊息}}
                </div>
        </div>
</div>

javascript
====
this.toast訊息 = 訊息;
var toastEl = document.querySelector(`#toast1`);
(new bootstrap.Toast(toastEl)).show();    

radio & checkbox 美化

<div class="form-check"><label class="form-check-label"><input class="form-check-input" type="radio" value="1" />{{日期時間}}</label><label class="form-check-label"><input class="form-check-input" type="checkbox" style="margin-left:1em" />登記午餐</label></div>
<div class="form-check"><label class="form-check-label"><input class="form-check-input" type="radio" value="2" />下次再邀約</label></div>

<style>
.form-check-input {
margin-right: 0.5em;
}
</style>

2023年1月2日 星期一

升級到 EF 7 遇到的問題

呼叫 savechanges() 遇到錯誤

Could not save changes because the target table has database triggers. Please configure your entity type accordingly, see https://aka.ms/efcore-docs-sqlserver-save-changes-and-triggers for more information. : 如果 DML 陳述式包含 OUTPUT 子句但不含 INTO 子句,陳述式的目標資料表 'OrderItem' 就不可以有任何啟用的觸發程序。

這是因為EF7 使用新的技術寫入資料庫,但 sql server table 有trigger 時不支援此技術,可改為舊的方式處理

參考資料

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

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