views:

57

answers:

3

It seems to me that I have to retrieve an object before I delete it with entity framework like below

var customer = context.Customers.First(c => c.Id = 1);

context.DeleteObject(customer);

context.Savechanges();

So I need to hit database twice. Is there a easier way?

Thanks

A: 

If you're using EF 1.0, that is the most concise way to do it. There may be other ways but they're more trouble than they're worth IMHO.

Dave Swersky
A: 

Duplicate

thekaido
A: 

If you dont want to query for it just create an entity, and then delete it.

Customer customer  = new Customer() {  Id = 1   } ; 
context.AttachTo("Customers", customer);
context.DeleteObject(customer);
context.Savechanges();
Nix