English 中文(简体)
删除一些相关记录
原标题:Linq to sql - delete some related records

I ́m使用linq to sql,我有许多表格,有外国钥匙,导致用户Id。

有可能在删除后清理其中一些外国表格。

例如,我希望用户简介(其他表格)自动删除,而不是用户论坛员额。

这样做是可能的,还是我必须用法典处理吗?

最佳回答

我认为,link是非常有用的。

LINQ to SQL does not support or recognize cascade-delete operations. If you want to delete a row in a table that has constraints against it, you must complete either of the following tasks:

  • Set the ON DELETE CASCADE rule in the foreign-key constraint in the
    database.

  • Use your own code to first delete the child objects that prevent the parent object from being deleted.

问题回答

我不相信守则,但你会把《词汇》放在删除选项中吗?





相关问题
nhibernate hasmany when not using foreign key

Let say I have a request table, that looks as follows: RequestId INT ReferenceNumber VARCHAR Each request is logged in a requestlog table. There are no foreign keys between the tables: ...

Handling foreign key exceptions in PHP

What is the best way in PHP to handle foreign key exceptions on a mysql database? Is there a mysql class that can be used to simplify any code? Ideally, what I want to do, as an example, is to try to ...

Oracle cyclic foreign key references issues

I ve been racking my brain trying to come up with a solution to this. For a database class, I need to implement the following: Table HUSBANDS: (Name Varchar2(10)) (Wife Varchar2(10)) Table WIVES: (...

Issues when adding foreign key

When I m trying to create a foreign key linked to a primary key in another table I get: #1452 - Cannot add or update a child row: a foreign key constraint fails (`fayer`.`#sql-225c_1d3`, CONSTRAINT `#...

Can someone explain MySQL foreign keys

I know what they are my question is, how do you link them or are they automatically linked when you have identical names in different tables. Here is an example: Say I have an [orders] table and a [...

How to emulate tagged union in a database?

What is the best way to emulate Tagged union in databases? I m talking about something like this: create table t1 { vehicle_id INTEGER NOT NULL REFERENCES car(id) OR motor(id) -- not valid ... } ...

热门标签