gpt4 book ai didi

c# - Entity Framework 6 Create() 与 new

转载 作者:可可西里 更新时间:2023-11-01 08:06:08 26 4
gpt4 key购买 nike

这两种方式添加实体有什么区别?

MyEntity me = new MyEntity();
entities.myentities.Add(me);

对比

MyEntity me = entities.myentities.Create();

第二个例子还需要加“我”吗?如果是这样,是否有某种优势,无论是一种方式还是另一种方式?

非常感谢!

最佳答案

MyEntity me = new MyEntity();

将创建一个新的MyEntity实例

MyEntity me = entities.myentities.Create();

将创建 MyEntity 的代理包装实例(假设您的上下文配置为创建代理)

This proxy overrides some virtual properties of the entity to insert hooks for performing actions automatically when the property is accessed. For example, this mechanism is used to support lazy loading of relationships.

from here

关于c# - Entity Framework 6 Create() 与 new,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31405958/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com