我们已经研究出如何使用“sql like”语法对实体进行数据绑定:
var countryQuery = from c in ShopEntities.ShippingCountries
orderby c.Order
select new { c.ShippingCountryId, c.Name};
Country.DataValueField = "ShippingCountryId"; //country is a DropDownList
Country.DataTextField = "Name";
Country.DataSource = countryQuery;
DataBind();
但是你如何使用“点”语法
来完成上述操作var countryQuery = ShopEntities.ShippingCountries.OrderBy(s => s.Order).what to put here????
Country.DataValueField = "ShippingCountryId";
Country.DataTextField = "Name";
Country.DataSource = countryQuery;
DataBind();
答案 0 :(得分:1)
请参阅LINQ How to select more than 1 property in a lambda expression?
基本上只是:
.Select(c => new { c.ShippingCountryId, c.Name }).ToList();
答案 1 :(得分:1)
与orderBy
的方式相同ar countryQuery = ShopEntities.ShippingCountries.OrderBy(s => s.Order).Select(s => new classref {ShippingCountryId = s.ShippingCountryId,Name = s.Name})
这一个
ar countryQuery = ShopEntities.ShippingCountries.OrderBy(s => s.Order).Select(s => new { s.ShippingCountryId, s.Name})