tabs ↹ over ␣ ␣ ␣ spaces

by Jiří {x2} Činčura

SomeEntitySet.AddObject vs. AddToSomeEntitySet methods

12 Aug 2011 1 mins 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 .NET, C# and Firebird expert. He focuses on data and business layers, language constructs, parallelism, databases and performance. For almost two decades he contributes to open-source, i.e. FirebirdClient. He works as a senior software engineer for Microsoft. Frequent speaker and blogger at www.tabsoverspaces.com.