0

我在 LINQ 领域有点新。我有一个这样的删除查询:

DELETE FROM Table1 WHERE FK IN (SELECT ID FROM Table2 WHERE UserId = @UId)

如何将其更改为 LINQ 查询?

4

1 回答 1

0

这应该给你一个想法

var itemQuery = from cartItems in db.SalesOrderDetails
              where cartItems.SalesOrderID == 75144
              select cartItems.ProductID;


var myProducts = from p in db.Products
                where itemQuery.Contains(p.ProductID)
                select p;

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

try
{
    db.SubmitChanges();
}
catch (Exception e)
{
    Console.WriteLine(e);
    // Provide for exceptions.
}
于 2012-06-30T18:19:55.587 回答