Create<Object> vs new <Object> in Entity Framework

前端 未结 2 1017
花落未央
花落未央 2020-12-31 09:42

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

Dim myObject As SpecialThing = New SpecialThing()

The

2条回答
  •  梦毁少年i
    2020-12-31 10:14

    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 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

提交回复
热议问题