Reputation:
I want insert a row in my table with linq in asp.net, and I've some troubles with that. I search a lot about this and I found the same solution in everywhere:
context.entity.InsertOnSubmit(variable);
So, I haven't the InsertOnSubmit method, I need do something special to use it? I have using System.Web.Linq
.
To overtake this problem I tried with:
context.entity.Add(variable);
context.SaveChanges();
And the result was an error like:
"An error occurred while updating the entries. See the inner exception for details."
DETAILS: "Invalid object name 'ConnectionStringModelStoreContainer.user'."
What do you suggest?
Upvotes: 0
Views: 1159
Reputation:
I found the solution of my problem.
In this article explain exactly what I need to do: http://blogs.msdn.com/b/adonet/archive/2011/01/29/using-dbcontext-in-ef-feature-ctp5-part-4-add-attach-and-entity-states.aspx?Redirected=true
Upvotes: 0
Reputation: 9499
Linq2Sql
concept to add rows to the database. SubmitChanges is used to save the changes.In your case, it looks like you're using Entity Framework.
Check your EDMX file and database to see any table mismatches.
Specifically,
Upvotes: 1
Reputation: 2135
When using Linq2SQL, you will need to access the table you are trying to insert into with context.TableName.InsertOnSubmit(value)
where TableName is the name of the table in your dbml file and the value is an isntance of that class that was created for you. Once you have called the InsertOnSubmit()
method, you need to call the context.SubmitChanges()
method to actually save it to the table. Also, depending on how you created your dbml file, the table name on the context my be plural. ex: For a User
table, it may look like context.Users.InsertOnSumbit(user);
Upvotes: 0