Answer the question
In order to leave comments, you need to log in
C# EF SQL how to make a query?
Please tell me how to delete certain rows in the database if they are 1 day overdue.
public string value { get; set; }
public DateTime date { get; set; }
Answer the question
In order to leave comments, you need to log in
Something like this: Class.Where(x => x.date < DateTime.Today.AddDays(-1));
Get all the objects and do what you need with them
Through EF:
1) Get rows by condition from the database.
2) Remove received rows by calling the Remove/RemoveRange method on the repository or how you get them.
Yes - you have to load first to uninstall, this is a limitation of pure EF. The data is raced twice.
Through SQL:
1) Write a SQL script.
Minus - it is better to avoid SQL when using EF, because when renaming properties, tables - scripts will need to be searched and edited separately. They are more difficult to test, change, etc.
Through an extension for EF:
1) We write context.BulkDelete(customers, options => CONDITION) and that's it.
We are looking for analogues https://entityframework-extensions.net/bulk-delete, there are free ones for sure.
In this case, we use EF, do not write SQL, and the data is not chased twice, the code is cleaner, more understandable, etc.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question