tabs ↹ over ␣ ␣ ␣ spaces

by Jiří {x2} Činčura

SomeEntitySet.AddObject vs. AddToSomeEntitySet methods

12 Aug 2011 Entity Framework

Is it better to call ObjectContext.SomeEntitySet.AddObject() or ObjectContext.AddToSomeEntitySet()? Short answer is: It doesn’t matter.

Long answer. The AddToSomeEntitySet method calls base.AddObject("SomeEntitySet", someEntitySet);, you can see it from generated code. The other method calls base.Context.AddObject(this.FullyQualifiedEntitySetName, entity);. Hence it’s almost the same. Only difference is in FullyQualifiedEntitySetName property that is used. So it might be little bit slower, but I think it’s unmesurable difference. Also take into account other parts of your application, honestly, where you’re probably wasting more time. 😎

What’s your preferred call?

Profile Picture Jiří Činčura is an independent developer focusing on data and business layers, language constructs, parallelism and databases. Specifically Entity Framework, asynchronous and parallel programming, cloud and Azure. He's Microsoft Most Valuable Professional and you can read his articles, guides, tips and tricks at www.tabsoverspaces.com.