[英]Distinct method does not work Entity Framework
在第一阶段,我如何获得随机相似的数据,但我尝试将不同的数据合并,但功能不起作用,
var turler= (from x in db.bird_table_ad
join e in db.kus_resim on x.tr_x equals e.kus_tur
where x.aile == item
select new GozlemTurleri
{
id = x.id,
kod = x.kod,
tr_x = x.tr_x,
en_x = x.en_x,
lt_x = x.lt_x,
turfotourl="image_resize.phpad="+e.altDIR+"/"+e.resim+"&yon="+(e.galeri=="fg"?"2":"HD2"),
aile = x.aile,
gfoto = x.gfoto
}).Distinct().ToList();
如果您尝试从数据库获取与tr_x
有关的不同记录,则可以在实体框架中使用GroupBy
。
这样您的代码就可以了。
.GroupBy(x => x.tr_x).Select(x => x.First()).ToList();
代替
.Distinct().ToList();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.