Andreas
Andreas

Reputation: 7248

LINQ Clear() don't remove rows from database

I have a db-table that looks like this:

CREATE TABLE ItemPrice
(
    [Identity]    INT    IDENTITY,
    Item_FK       INT    NOT NULL   REFERENCES Item([Identity]),
    PriceList_FK  INT    NOT NULL   REFERENCES PriceList([Identity]),
    Price         FLOAT  NOT NULL,
    PRIMARY KEY ([Identity])
)

If i then in my linq context use the Clear() on one of my PriceList instances like this where Current is a PriceList:

Current.ItemPrices.Clear();

The items in ItemPrice is not removed. PriceList_FK is just set to NULL and then the DB conflicts on the NOT NULL.

How do i force the database to remove all the rows.

Upvotes: 2

Views: 437

Answers (1)

Andreas
Andreas

Reputation: 7248

What i did was jut simply to call remove on the Table itself, not clear on the referring Objects, like this:

Database.Accounting.ItemPrices.DeleteAllOnSubmit(Current.ItemPrices);

(Accounting is the Linq data context)

Upvotes: 3

Related Questions