Nargzul
asked on
Entity framework: Delete objects that respects some conditions
Hi!
I only want to know if this is possible to delete, with Entity Framework 4.0 some objects directly by specifying conditions.
I know I can select all object and then do a foreach on them and delete them. the goal is to avoid to retrieve data only to delete them. So please don't provide me a solution like
foreach( MyObjectType myObject in DataContext.MyObjectType.W here( <conditionsHere>))
DataContext.MyObjectType.D eleteObjec t(myObject );
myObject.SaveChanges();
The goal is to have something like:
DataContext.MyObjectType.D elete.Wher e(m=> m.date<= someOtherDate);
I only want to know if this is possible to delete, with Entity Framework 4.0 some objects directly by specifying conditions.
I know I can select all object and then do a foreach on them and delete them. the goal is to avoid to retrieve data only to delete them. So please don't provide me a solution like
foreach( MyObjectType myObject in DataContext.MyObjectType.W
DataContext.MyObjectType.D
myObject.SaveChanges();
The goal is to have something like:
DataContext.MyObjectType.D
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You could execute an SQL comment directly by using the connection of the ObjectContext but it must be a correctly formed SQL syntax because the command is not checked at compile time but only at run-time.
ObjectContextInstance.Exec uteStoreCo mmand("SQL Statemens as a string", params Object[] parameters);
Documentation ObjectContext.ExecuteStore Command Method :
http://msdn.microsoft.com/en-us/library/system.data.objects.objectcontext.executestorecommand.aspx
ObjectContextInstance.Exec
Documentation ObjectContext.ExecuteStore
http://msdn.microsoft.com/en-us/library/system.data.objects.objectcontext.executestorecommand.aspx
ASKER