0

When deleting data related to an object in an HttpDelete call using Entity Framework Core, I can do this:

var video = _context.VideoList.Where(x => x.VideoId == nodeList.VideoId).FirstOrDefault();

But what if I have multiple rows that needed deleted using the same VideoId? Also the two entities are not related in the database(no foreign keys).

I've found answers that use a List then use RemoveRange, but I just need to delete potentially multiple records using the same ID...I know in SQL it would look like this:

DELETE FROM VideoList WHERE VideoId = '111xxx333aaa' 

Is there a way to do this in EF core?

Thanks!

1 Answer 1

1

You can do it in 2 steps :

  • Even if your entities are not related get them in an IEnumerable like a List

var videos = _context.VideoList.Where(x => x.VideoId == nodeList.VideoId).ToList();

  • And then remove them with a RemoveRange

_context.VideoList.RemoveRange(videos);

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.