创建<对象> VS全新<对象>在实体框架 [英] Create<Object> vs new <Object> in Entity Framework

查看:213
本文介绍了创建<对象> VS全新<对象>在实体框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个初始化/更新的实体对象。是否有任何危险使用

I've got an initializer/updater for an entity object. Is there any danger in using

Dim myObject As SpecialThing = New SpecialThing()

然后设置所有的值(使用已写入的更新),或者我需要使用:

Then setting all the values (using the updater that is already written), or do I need to use:

Dim myObject As SpecialThing = SpecialThing.Create()

有30个参数,并更新程序已经设定值/处理错误。只是希望重用code。

There are 30 parameters and the updater already sets the values/handles errors. Just looking to reuse that code.

推荐答案

如果您自己创建的对象,它不会被附加到上下文。您需要附加对象才能有变化更新中数据库。

If you create the object yourself, it won't be attached to the context. You'll need to attach the object in order to have changes update in the database.

Eventhough如果你使用Create方法创建实体,它不会被附加到上下文,这将在数据库保存由SaveChanges方法。 http://msdn.microsoft.com/en-美国/库/ gg696136(V = vs.113)的.aspx

Eventhough if you create Entity using Create Method, it will not be attached to the context and this will save in DB by SaveChanges method. http://msdn.microsoft.com/en-us/library/gg696136(v=vs.113).aspx

这篇关于创建<对象> VS全新<对象>在实体框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆