ITable<T>.DeleteAllOnSubmit() is absent?
As far as I see ITable<T> interface doesn't have DeleteAllOnSubmit() method that exists in ITable interface and in Table<T> class.
I am going to implement on my own something like this:
public static void DeleteAllOnSubmit<T>(this ITable<T> table, IEnumerable<T> entities)
{
entities.ForEach(entity=>table.DeleteOnSubm开发者_如何学编程it(entity);
}
Question 1: Is there any pitfalls here? If it was so easy Microsoft would implement that thierselves...
Question 2: Why that was not implmemented out-of-the box?
Having a look at the implementation of Table<TEntity>.DeleteAllOnSubmit<TSubEntity>() shows, that there isn't much more going on:
public void DeleteAllOnSubmit<TSubEntity>(IEnumerable<TSubEntity> entities) where TSubEntity: TEntity
{
if (entities == null)
{
throw Error.ArgumentNull("entities");
}
this.CheckReadOnly();
this.context.CheckNotInSubmitChanges();
this.context.VerifyTrackingEnabled();
foreach (TEntity local in entities.ToList<TSubEntity>())
{
this.DeleteOnSubmit(local);
}
}
So, I'd say: Your implementation is just fine.
BTW: There is no ForEach extension method for IEnumerable<T>.
Alternatively you could implement something to the effect of..
public static void DeleteAllOnSubmit<T>(this ITable<T> table, IEnumerable<T> entities)
{
table.Context.GetTable<T>().DeleteAllOnSubmit(entities);
}
Just traveling through the ITable<T> to the context specific table and calling its DeleteAllOnSubmit(). That way there isn't the deviation in the way you enumerate and delete all and the way the context does natively.
加载中,请稍侯......
精彩评论