使用linq将多个表的所有行添加到一个组中

时间:2017-03-24 13:31:18

标签: entity-framework linq

您好我正在尝试使用entityframework创建搜索查询 我正在做这样的事情

model = _context.articles.where(combination 1)
model2 = _context.tags.where(combination 2).select(x=> new {article=..})
model3 = _context.keywords.where(combination 3).select(x=> new {article=..})

我没有生成一个模型,因为它不可能或不能创建这样的查询,但现在因为我有3个具有相似列的模型,我想要做的就是将它们合并为一个并删除重复项。 我不知道这是不是很好的做法,但有可能吗?

1 个答案:

答案 0 :(得分:0)

使用uniondistinct方法如下:

var result =  model.Union(model2).Union(model3).Distinct().ToList();