我有 using (ProjectEntities myEntities = new ProjectEntities ())
{
var q = (from c in myEntities.Customers orderby c.Name select c.Name);
DropDownList1.DataSource = q.ToList();
DropDownList1.DataBind();
}
从此查询中获取数据:
ng-model
如何获得唯一的名称?
答案 0 :(得分:3)
只需添加 Distinct
var q = (from c in myEntities.Customers orderby c.Name select c.Name);
DropDownList1.DataSource = q.ToList().Distinct();
或查询本身,
var q = (from c in myEntities.Customers orderby c.Name select c.Name).Distinct();
答案 1 :(得分:1)
您可以对从当前linq表达式获得的结果调用Distinct()
方法。
var q = (from c in myEntities.Customers orderby c.Name select c.Name).Distinct();
或
var q = myEntities.Customers.OrderBy(s=>s.Name).Select(f=>f.Name).Distinct();