开发者

How do you databind entities to WebForm controls with dot syntax?

We have worked out how to databind entites with "sql like" syntax:

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();

But how do you do the above with the "dot" syntax

var countryQuery = ShopEntities.ShippingCountries.OrderBy(s => s.Order).what to put here????

Country.DataValueField = "ShippingCountryId";
Country.DataTextFiel开发者_如何学Pythond = "Name";
Country.DataSource = countryQuery;
DataBind();


See LINQ How to select more than 1 property in a lambda expression?

Basically just:


.Select(c => new { c.ShippingCountryId, c.Name }).ToList();


The same way you did for orderBy

ar countryQuery = ShopEntities.ShippingCountries.OrderBy(s => s.Order).Select(s => new classref {ShippingCountryId = s.ShippingCountryId,Name = s.Name})

ot this one

ar countryQuery = ShopEntities.ShippingCountries.OrderBy(s => s.Order).Select(s => new { s.ShippingCountryId, s.Name})
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜