Here's some of my database design on my assignments
Customer -------- CustomerID (PK) Cake ------- CakeID (PK) Cart ------- CustomerID (PK, FK) CakeID (PK, FK)
I'd like to make a function
clearUserCart(User user) in my Cart Repository class but I have no idea how to make function to delete all rows with specified user.
I have figured out how to do it, just use
getCartOfUser(User user) which returns
List<Cart>. Then do foreach loop to remove.
In SQL, it could be achieved just by one line
DELETE FROM Cart WHERE CustomerID = <the cust id>, is there an equivalent one line statement in entity framework?
If you are using EF 6, you can use the RemoveRange method.
So it could look something like this;
context.Cart.RemoveRange(cartItem => cartItem.CustomerID == CustomerToDelete);