我正在尝试使用制药公司(例如 Bayer、Medley 等)填充下拉列表.而且,我从 DB 获取这些名称,并且这些名称在 DB 中重复,但 ID 不同.
I'm trying to populate a Drop down list with pharmaceutical companies, like Bayer, Medley etc. And, I'm getting theses names from DB and theses names are repeated in DB, but with different id's.
我正在尝试使用 Linq Distinct(),但我不想使用相等比较器.还有别的办法吗?
I'm trying to use Linq Distinct(), but I don't want to use the equality comparer. Is there another way?
我的下拉列表必须填写id和公司名称.
My drop down list must be filled with the id and the name of the company.
我正在尝试类似的东西:
I'm trying something like:
var x = _partnerService
.SelectPartners()
.Select(c => new {codPartner = c.codPartner, name = c.name})
.Distinct();
这是在 ddl 中显示重复的公司.
This is showing repeated companies in ddl.
谢谢!
以下表达式将仅选择不同的公司并返回第一个出现的公司及其 ID.
The following expression will select only distinct companies and return the first occurence with its id.
partnerService.SelectPartners().GroupBy(p => p.Name).Select(g => g.First());
这篇关于Linq Distinct() 按名称填充带有名称和值的下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!