我能问一下这是否是使用EF删除整个数据库表的正确方法吗?
Department表将设施与DepartmentID连接,
Facility表将Facility Reservation与FacilityID连接起来,
我需要从设备预订表中删除所有记录。
有人能指导我并告诉我这是否正确吗?
谢谢您!
db.Database.ExecuteSqlCommand(
"DELETE FacilityReservation FROM Department INNER JOIN Facility ON Department.DepartmentID = Facility.DepartmentID " +
"INNER JOIN FacilityReservation ON Facility.FacilityID = FacilityReservation.FacilityID WHERE Department.DepartmentID =" + departmentID);
最佳答案
不,当然不需要,您需要从中删除,当您进行联接时,您需要另一个“FROM”。
你可能想要这个:
DELETE FROM FacilityReservation
INNER JOIN Facility
ON Facility.FacilityID = FacilityReservation.FacilityID
INNER JOIN Department
ON Department.DepartmentID = Facility.DepartmentID
WHERE Department.DepartmentID = @departmentID;