![](/img/trans.png)
[英]Entity Framework 6 - How can I view the SQL that will be generated for an insert before calling SaveChanges
[英]How can I check which property of the entity is modified before SaveChanges?
我在asp.net mvc5中使用EF。 我想要在更新/編輯實體時修改的屬性。 我可以使用context.Entry(blog).Property("Name").IsModified = true;
來獲取它context.Entry(blog).Property("Name").IsModified = true;
但是為此,我必須檢查該實體的每個屬性。 有什么方法可以獲取直接的屬性名稱和更新的值?
要獲取已更改的屬性名稱:
var entry = context.Entry(myEntity);
var changedProperties = entry.CurrentValues.PropertyNames
.Where(p => entry.Property(p).IsModified);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.