1

I'm saving entities/records with the EF, but i'm curious if there is another way of doing it.

I receive a class from a MVC controller method, so basicly i have all the info: the class's properties, including the primary key. Without EF i would do a Sql update (update table set a=b, c=d where id = 5), but with EF i got no further than this:

Get an object with ID of 5 Update the (existing) object with the new object Submitchanges.

What bothers me is that i have to get the object from the database first, where i have all the info to do an update statement.

Is there another way of doing this?

2
  • so you just dont like having to translate whatever you have to the entity object? Commented Apr 3, 2010 at 18:25
  • correct, now i'm typing ExistingPeson.Name = PostedPerson.Name etc. Commented Apr 6, 2010 at 12:03

2 Answers 2

5

No, the pattern is typically:

  1. select the entity
  2. Update the properties
  3. Save your changes

Another SO question on this topic.

Sign up to request clarification or add additional context in comments.

Comments

-2
u will have to create an object, update the properties and then savechanges 

try this 

using (var context = new NorthWindEntities())
{
    Product prod = new Product();
    prod.Name = "Car toy";
    prod.Price = "10.00";

    prod.SaveChanges();//this method will actuayll save the changes

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.