LINQ选择项目不在列表中的位置

Sha*_*eKm 2 linq asp.net-mvc linq-to-entities asp.net-mvc-3

我需要插入不在db中的项目.所以我试图运行以下(这不起作用):

 foreach(var rep in model.Reps.Where(x => x.Value != 
    this.dictionaryItemRepository.List().Select(y => y.Value)))
Run Code Online (Sandbox Code Playgroud)

其中model.Reps是:

 public ICollection<DictionaryItemBrand> Reps { get; set; }
Run Code Online (Sandbox Code Playgroud)

从模型绑定器返回

我正在尝试做一个foreach循环 - > 选择model.Reps中的所有项目,这些项目在存储库中尚不存在.

我该怎么做?谢谢

San*_*ath 5

这应该是它.

var notInRepo = from rep in model.Reps
                where (!this.dictionaryItemRepository.Contains(rep.Value))
                select rep.Value;
Run Code Online (Sandbox Code Playgroud)