且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法更新asp.net-core 2.2 c#中的记录

更新时间:2023-02-17 08:07:39

在大多数情况下,EF会自动检测哪些字段需要更新,并且在上下文中(带有实体)具有update函数是对说您正在尝试做不必要的事情.

In most cases, EF will automatically detect which fields need updating, having an update function in a context (that takes an entity) is a red flag to say you are trying to do something that is not required.

EF在幕后做了很多事情,因此您不必考虑它们.这就是其中之一.

EF does a lot of things behind the scenes, so you don't have to think about them. This is one of them.

我怀疑您读了一个非常老的博客,内容涉及10年前某人必须如何做才能使EF更新记录.

I suspect you read a really old blog about how someone 10 years ago had to do something to get EF to update a record.

此外,从上下文类中删除该update函数,以便没有其他人绊倒它.

Also, remove that update function from your context class, so that no-one else trips up on it.