• <tfoot id='b5ol3'></tfoot>
    <i id='b5ol3'><tr id='b5ol3'><dt id='b5ol3'><q id='b5ol3'><span id='b5ol3'><b id='b5ol3'><form id='b5ol3'><ins id='b5ol3'></ins><ul id='b5ol3'></ul><sub id='b5ol3'></sub></form><legend id='b5ol3'></legend><bdo id='b5ol3'><pre id='b5ol3'><center id='b5ol3'></center></pre></bdo></b><th id='b5ol3'></th></span></q></dt></tr></i><div id='b5ol3'><tfoot id='b5ol3'></tfoot><dl id='b5ol3'><fieldset id='b5ol3'></fieldset></dl></div>

  • <legend id='b5ol3'><style id='b5ol3'><dir id='b5ol3'><q id='b5ol3'></q></dir></style></legend>
    • <bdo id='b5ol3'></bdo><ul id='b5ol3'></ul>

    <small id='b5ol3'></small><noframes id='b5ol3'>

        实体框架附加/更新混淆 (EF Core)

        Entity Framework Attach/Update confusion (EF Core)(实体框架附加/更新混淆 (EF Core))

            • <tfoot id='O9QsC'></tfoot>
                <tbody id='O9QsC'></tbody>

              <small id='O9QsC'></small><noframes id='O9QsC'>

              1. <legend id='O9QsC'><style id='O9QsC'><dir id='O9QsC'><q id='O9QsC'></q></dir></style></legend>
                <i id='O9QsC'><tr id='O9QsC'><dt id='O9QsC'><q id='O9QsC'><span id='O9QsC'><b id='O9QsC'><form id='O9QsC'><ins id='O9QsC'></ins><ul id='O9QsC'></ul><sub id='O9QsC'></sub></form><legend id='O9QsC'></legend><bdo id='O9QsC'><pre id='O9QsC'><center id='O9QsC'></center></pre></bdo></b><th id='O9QsC'></th></span></q></dt></tr></i><div id='O9QsC'><tfoot id='O9QsC'></tfoot><dl id='O9QsC'><fieldset id='O9QsC'></fieldset></dl></div>
                  <bdo id='O9QsC'></bdo><ul id='O9QsC'></ul>
                • 本文介绍了实体框架附加/更新混淆 (EF Core)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  据我了解,当调用更新"时,特定实体中的每个属性都会被修改.

                  As I understand, when "Update" is called, every property within a specific entity is modified.

                  另一方面,附加"方法在未修改"状态下启动实体.然后,当对特定属性进行操作时,仅修改该特定属性.所以附加"对于单个属性更改更有用,而更新"在您要更新实体中的每个属性时更有用(我的理解可能是错误的).

                  The "Attach" method, on the other hand, starts the entity off in the "Unmodified" state. Then, when an operation takes place on a particular property, that specific property only is modified. So "Attach" is more useful for individual property changes, and "Update" is more useful when you want to update every property in the entity (I may be wrong in this understanding).

                  但是,我不明白的是,在属性更改期间这两种方法都没有被调用时会发生什么.例如,考虑一个名为students"的表的示例:

                  However, what I don't understand is what happens when neither of these two methods are called during a property change. For instance, consider an example with a table called "students":

                  student.City = "Calgary";
                  student.Name = "John Smith";
                  database.SaveChanges();
                  

                  由于我们没有将实体中的任何属性标记为已修改,因此上述代码生成的查询有何不同?

                  As we are not marking any property in the entity as modified, how will the generated query from the above code differ?

                  推荐答案

                  考虑以下代码:

                  students entity = new students() {
                      Id = 1,
                      City = "New York",
                      Name = "Sam"
                  };
                  using(SomeContext ctx = new SomeContext())
                  {
                      ctx.Entry(entity).State = EntityState.Modified;
                      ctx.SaveChanges();
                  }
                  

                  假设我们在数据库中有一条 id = 1 的记录,上面的代码将更新数据库中的那个实体.

                  Assuming we have a record with id = 1 in the database, the above code will update that entity in the database.

                  Attach 用于当您知道一个实体已经存在于数据库中,但想要进行一些更改,同时在您已经进行更改时将状态更改为已修改.

                  Attach is used when you know that an entity already exists in the database but want to make some changes while change state to modified when you have already made the changes.

                  这篇关于实体框架附加/更新混淆 (EF Core)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Adding and removing users from Active Directory groups in .NET(在 .NET 中的 Active Directory 组中添加和删除用户)
                  set equality in linq(在 linq 中设置相等)
                  HashSet conversion to List(HashSet 转换为 List)
                  How to set timeout for webBrowser navigate event(如何为 webBrowser 导航事件设置超时)
                  Test whether two IEnumerablelt;Tgt; have the same values with the same frequencies(测试两个IEnumerablelt;Tgt;具有相同频率的相同值)
                  How do you determine if two HashSets are equal (by value, not by reference)?(您如何确定两个 HashSet 是否相等(按值,而不是按引用)?)

                  <legend id='BUGe0'><style id='BUGe0'><dir id='BUGe0'><q id='BUGe0'></q></dir></style></legend><tfoot id='BUGe0'></tfoot>

                    <i id='BUGe0'><tr id='BUGe0'><dt id='BUGe0'><q id='BUGe0'><span id='BUGe0'><b id='BUGe0'><form id='BUGe0'><ins id='BUGe0'></ins><ul id='BUGe0'></ul><sub id='BUGe0'></sub></form><legend id='BUGe0'></legend><bdo id='BUGe0'><pre id='BUGe0'><center id='BUGe0'></center></pre></bdo></b><th id='BUGe0'></th></span></q></dt></tr></i><div id='BUGe0'><tfoot id='BUGe0'></tfoot><dl id='BUGe0'><fieldset id='BUGe0'></fieldset></dl></div>

                    <small id='BUGe0'></small><noframes id='BUGe0'>

                    • <bdo id='BUGe0'></bdo><ul id='BUGe0'></ul>

                            <tbody id='BUGe0'></tbody>