Code: Select all
CREATE TABLE animals (
Id INTEGER PRIMARY KEY AUTO_INCREMENT,
Description VARCHAR(512),
Timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
CREATE TABLE animal_events (
Id INTEGER PRIMARY KEY AUTO_INCREMENT,
Begin DATETIME NOT NULL,
AnimalId INT,
Timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY animal_fk(AnimalId) REFERENCES animals(Id) ON DELETE CASCADE
);
This is something that is done by the database, triggered by the delete on cascade clause whenever I delete an animal. Correct?
But in the sql trace I see many individual delete commands. Why is the entity framework/devart doing this?
Code: Select all
DELETE FROM rfidfarm.animal_events WHERE Id = 1
DELETE FROM rfidfarm.animal_events WHERE Id = 2
DELETE FROM rfidfarm.animal_events WHERE Id = 3
...
My test code:
Code: Select all
using (var uow = _modelFactory.CreateUnitOfWork())
{
var animal = uow.Animals.GetById(2);
var animalEventCount = animal.AnimalEvents.Count;
uow.Animals.Delete(animal);
uow.SaveChanges();
}