Linq to sql LINQ Clear()don';t从数据库中删除行
我有一个db表,如下所示:Linq to sql LINQ Clear()don';t从数据库中删除行,linq-to-sql,Linq To Sql,我有一个db表,如下所示: 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, PR
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])
)
Database.Accounting.ItemPrices.DeleteAllOnSubmit(Current.ItemPrices);
如果我在linq上下文中使用Clear()
在我的PriceList
实例中,其中Current
是PriceList
:
Current.ItemPrices.Clear();
ItemPrice
中的项目不会被删除PriceList\u FK
仅设置为NULL
,然后数据库在非NULL
上发生冲突
如何强制数据库删除所有行。我所做的只是在表本身上调用remove,而在引用对象上调用remove,如下所示:
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])
)
Database.Accounting.ItemPrices.DeleteAllOnSubmit(Current.ItemPrices);
(记帐是Linq数据上下文)