linq to sql batch delete

后端 未结 4 1145
一生所求
一生所求 2021-01-13 01:06

I have the following DB: Posts which have an Id, Tags also with Id, and TagsToPosts table which have T

4条回答
  •  心在旅途
    2021-01-13 01:42

    Have you looked at the Linq Except operator?

    For example:

    var toDelete = (from t in TagsToPost
                    select t).Except(from nt in newList
                                     select nt, new TagComparer());
    
    class TagComparer: IEqualityComparer
    {
        public bool Equals(TagsToPosts x, TagsToPosts y)
        {
             return x.Tag.Equals(y.Tag, CompareOptions.Ordinal);
        }
    }
    

提交回复
热议问题