简体   繁体   中英

Is the primary key property also marked as modified when use DbSet<T>.Update() method?

The definition of DbSet.Update() is :

"Begins tracking the given entity.... ...All properties of the entity will be marked as modified."

does it include the primary key property? If the primary key property also marked as modified, why the primary key in not in generated SQL's Set [primarykey] = XXX ?(where XXX should be the same primary key value as the one in database)

I suspect the answer is no, but you can check this for yourself.

DbSet.Update returns "The EntityEntry for the entity", which you can use to see which properties it has marked as modified. For example:

var entity = dbContext.MyTable.Update(myRecord);
foreach (var modifiedProperty in entity.Properties.Where(p => p.IsModified)) {
    Console.Write($"The {modifiedProperty.Metadata.Name} property is marked as modified");
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM