I'm using ExecuteStoreCommand to facilitate bulk deletes.
This Works
// ExecuteStoreCommand syntax via http://stackoverflow.com/a/13024320/740639
// Delete all of today's events
DateTime eventDate = DateTime.Now;
string sql = "DELETE FROM EventCalendar WHERE EventDate = {0}";
context.ObjectContext.ExecuteStoreCommand(sql, new object[] { eventDate });
I want to do this, but it does not work
I get an ArgumentException: "No mapping exists from object type System.DateTime[] to a known managed provider native type."
// Delete all of the events for the past 3 days
DateTime[] eventDates = new DateTime[] {
DateTime.Now.AddDay(-1),
DateTime.Now.AddDay(-2),
DateTime.Now.AddDay(-3)
};
string sql = "DELETE FROM EventCalendar WHERE EventDate IN ({0})";
context.ObjectContext.ExecuteStoreCommand(sql, new object[] { eventDates });
Proposed Solution
I could convert my DateTime[] into the string "'2013-06-24', '2013-06-23', '2013-06-22'" and pass that as the parameter, but that seems like a hack.
I know there are libraries that add bulk delete support to EF, but I don't want to go that route at this time.
Any suggestions?