views:

43

answers:

2

I have this e.g. code:

    var list = (from item in db.Table
        select item).ToList();

[do processing where I modify,add,remove items to the list with a DX GridControl] [Ensure inserted items] [I can see that item(s) are not in the list]

db.SubmitChanges();

Changes not reflecting the DataBase for removed items. What is wrong?

A: 

Do you apply your changes with db.SubmitChanges(); method on your data Context? Example from msdn:

var deleteOrderDetails =
    from details in db.OrderDetails
    where details.OrderID == 11000
    select details;

foreach (var detail in deleteOrderDetails)
{
    db.OrderDetails.DeleteOnSubmit(detail);
}

try
{
    db.SubmitChanges();
}
catch (Exception e)
{
    Console.WriteLine(e);
    // Provide for exceptions.
}

Here is the source: http://msdn.microsoft.com/en-us/library/bb386925.aspx

I'm not sure that you can populate the changes from your List to the database if this is what you're trying to achieve.

anthares
So i should keep a list with deleted Id's and DeleteInSubmit(Id). This makes sense...i'll try.
No you should provide Entity objects to DeleteOnSubmit to put them into a pending delete state
anthares
The one who downvoted me, could you explain why ?
anthares
+1  A: 

You cannot modify the list in order to update the database. You have to modify the database entity collections. For example: db.Table.Remove(instance)

Edit: I believe the above syntax is EF4 only. For the original EF, you need to use DeleteOnSubmit, which is a method on your entity container.

David Pfeffer
I guess anthares is telling the same thing!