开发者

LINQ select where item is not in list

开发者 https://www.devze.com 2023-02-18 06:30 出处:网络
i need to insert items that are not in db. so i\'m trying to run the following (which doesn\'t work):

i need to insert items that are not in db. so i'm trying to run the following (which doesn't work):

 foreach(var rep in model.Reps.Where(x => x.Value != 
    this.dicti开发者_Go百科onaryItemRepository.List().Select(y => y.Value)))

where model.Reps is:

 public ICollection<DictionaryItemBrand> Reps { get; set; }

returned from model binder

I'm trying to do a foreach loop -> select all items from model.Reps that do NOT yet exist in repository.

how can i do it? thanks


This should be it.

var notInRepo = from rep in model.Reps
                where (!this.dictionaryItemRepository.Contains(rep.Value))
                select rep.Value;
0

精彩评论

暂无评论...
验证码 换一张
取 消