I am following this tutorial:
http://pattersonc.com/blog/2009/04/01/using-mysql-with-entity-framework-and-aspnet-mvc-%E2%80%93-part-i/
In the tutorial, there is a method that saves an object to the database using Entity Framework:
mySqlEntities.AddToProductSet(product);
Instead of creating a product table, I have created a table called user
. I cannot however find any method that is like AddToUser
or AddToUserSet
within the mySqlEntities
object. I have followed everything bang on.
no... there are no such methods... you need to write something like this:
mySqlEntities.Products.Add(product);
That article is outdated and looks like it has examples with Entity Framework 4, which generated ObjectContext
with methods like AddToSetName. These methods was marked as deprecated in later releases of Entity Framework and currently completely gone:
/// <summary>
/// Deprecated Method for adding a new object to the Products EntitySet.
/// Consider using the .Add method of associated ObjectSet<T> property instead.
/// </summary>
public void AddToProducts(Product product)
{
base.AddObject("Products", product);
}
On Entity Framework 5 or 6 you will have DbContext
generated without any additional methods for sets. As Zdravko correctly pointed, you should use context.SetName.Add
method to add entity to set.