DAL.DALDataContext dataContext = new DAL.DALDataContext();
var matchEntryId = from u in dataContext.EntryKeywordMenu
join o in dataContext.Keywords
on u.KeywordID equals o.KeywordID
where keywordList.Contains(o.keywordName)
select new { entryId = u.EntryID };
以上代码返回的entryId包含重复值,我不想写多余的代码去判重,如何改写才能去重呢?
var matchEntryId =(from u in dataContext.EntryKeywordMenu
join o in dataContext.Keywords
on u.KeywordID equals o.KeywordID
where keywordList.Contains(o.keywordName)
select new { entryId = u.EntryID }).Distinct();
在查询数据库时 不会立即去查 只会在你需要使用这些数据时才会去查询 这就是所谓的 LINQ延迟特性但是 DISTICT TOLIST等等这些操作符 是非延迟操作符
他会在代码执行到它们那时 立即去查询数据库 将数据加载到内存中 破坏了LINQ的延迟特性