On Sat, 2010-01-23 at 05:37 -0800, Truezplaya wrote:
> I am currently trying to delete a car from my Db but i keep getting a
> object not attached error can anyone help?

>From the Table<T>.DeleteOnSubmit() documentation [0]:

        Disconnected entities must first be attached before they can be
        deleted.

In short, you can't do what you're doing.  You can only delete an entity
which has been previously queried.

Thus, what you need to do is this:

        db.CarDetail.DeleteAllOnSubmit(
                db.CarDetail.Where(c => c.Make == makeID &&
                        c.Year == year && 
                        c.Model == model));

Alternatively:

        var car = db.CarDetail.Single(c => c.Make == makeID &&
                        c.Year == year && 
                        c.Model == model);
        db.CarDetail.DeleteOnSubmit(car);

 - Jon

[0] http://msdn.microsoft.com/en-us/library/bb763473.aspx


-- 
You received this message because you are subscribed to the Google Groups 
"DbLinq" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/dblinq?hl=en.

Reply via email to