3 methods for adding a "Product" through Entity Framework. What's the difference?
Posted
by Kohan
on Stack Overflow
See other posts from Stack Overflow
or by Kohan
Published on 2010-05-11T13:19:10Z
Indexed on
2010/05/11
13:24 UTC
Read the original article
Hit count: 463
Reading this MSDN article titled "Working with ObjectSet (Entity Framework)" It shows two examples on how to add a Product.. one for 3.5 and another for 4.0.
http://msdn.microsoft.com/en-us/library/ee473442.aspx
Through my lack of knowledge I am possibly completely missing something here, but i never added a Product like this:
//In .NET Framework 3.5 SP1, use the following code: (ObjectQuery)
using (AdventureWorksEntities context = new AdventureWorksEntities())
{
// Add the new object to the context.
context.AddObject("Products", newProduct);
}
//New in .NET Framework 4, use the following code: (ObjectSet)
using (AdventureWorksEntities context = new AdventureWorksEntities())
{
// Add the new object to the context.
context.Products.AddObject(newProduct);
}
I would not have done it either way and just used:
// (My familiar way)
using (AdventureWorksEntities context = new AdventureWorksEntities())
{
// Add the new object to the context.
context.AddToProducts(newProduct);
}
What's the difference between these three ways?
Is "My way" just another way of using an ObjectQuery?
Thanks, Kohan
© Stack Overflow or respective owner