I am very new to linq to sql and I am not sure how to actually delete a record.

So I been looking at this tutorial

http://weblogs.asp.net/scottgu/archive/2007/05/19/using-linq-to-sql-part-1.aspx

So for Update they have

NorthwindDataContext db = new NorthwindDataContext();

Product product = db.Products.Single(p => p.ProductName == "Toy 1");

product.UnitPrice == 99;
product.UnitsInStock = 5;

db.SubmitChanges();

For delete they have

NorthwindDataContext db = new NorthwindDataContext();

var toyProducts = from p in db.Producsts
              where p.ProductName.Contains("Toy")
                  select p;

db.Products.RemoveAll(toyProducts);

db.SubmitChanges();

So do I have to query every time, to get the record in order to delete that record? Like I can sort of see doing this with update since you need to give it a record which to update first and then make the changes so I understand the querying part but not with delete.

Like can't you just send in what you want to delete and it goes and deletes it? why do you have to first get it and then tell it to be deleted?

Is that not 2 hits on the database?

Also I have foreign key relationship that I am trying to get to work. So I have this

public ViewResult(string param1, string param2)
{
   Table A = new Table A
   A.Field1 = param1;
   A.Field2 = param2;

   Delete(A);
}

private void Delete(Table A)
{
   DbContext.A.DeleteAllOnsubmit(A.TableB);
   DbContext.A.DeleteAllOnSubmit(A.TableC);
   DbContext.A.DeleteOnSubmit(A);

}

So this fails it comes up with this message "Cannot remove an entity that has not been attached."

So I can see why the first 2 lines would fail in the delete method, since I made a new object and their is nothing in the object th

Edit
Report