Linq 连接表记录删除
我有一个关于 linq delete 的问题。
我在数据库中有 2 个表,它们被连接起来。
第一个表:UserID、UserName、UserSurname、UserPhone、CompanyId
第二个表:CompanyId、CompanyName
第一个表 我有很多与第二个表相关的记录。
我想删除第二条记录中的一家公司,但首先我必须删除用户(超过1个)
如何使用linq删除它?
谢谢约翰,
I have a question about linq delete.
I have 2 table in database and they are joined.
First Table: UserID, UserName, UserSurname, UserPhone, CompanyId
Second Table: CompanyId, CompanyName
First Table I have many recods with related second table.
I want to delete one company in second record, But firtly I have to delete users (more than 1)
How can I delete it with using linq?
Thanks John,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果我正确理解您的问题,您想要删除用户记录,并删除关联的公司记录。也许最简单的方法是将数据库中的外键设置为级联删除外键。然后只需使用 Linq 删除要删除的用户记录即可。 SQL Server 将自动删除关联的公司记录。
If I understand your question correctly, you want to delete a User record, and have the associated Company record(s) deleted as well. Probably the easiest way to do this is to set up the foreign key in your database to be a cascading delete foreign key. Then just use Linq to delete the User records you want to delete. The associated Company records will be deleted automatically by SQL Server.
您可以使用它
来获得进一步的帮助,请告诉我。
you may use this
for farther help please let me know.