views:

190

answers:

1

Is it possible to get LINQ to SQL to delete a record using the PK, without loading the record first? Similar to NHibernate's proxy object functionality?

+7  A: 

You should be able to do it this way:

var person = new Person();
person.ID = someID;

using (var context = new DataContext(connString))
{
    context.Persons.Attach(person, false); //attach is as unmodified
    context.Persons.DeleteOnSubmit(person); //remove it
    context.SubmitChanges(); //submit changes to db
}
Joseph