c# - Refreshing LINQ query on ComboBox Selection Changed -
i want able enumerate query again once selection has changed in combo box. working there must better way this.
var cmbbox = (from c in db.addresses select c.city).distinct(); cmbq2.itemssource = cmbbox; #endregion } private void cmbq2_selectionchanged(object sender, selectionchangedeventargs e) { var q2 = c in db.customers join ca in db.customeraddresses on c.customerid equals ca.customerid join in db.addresses on ca.addressid equals a.addressid a.city == (string)cmbq2.selectedvalue select new { name = c.firstname, city = a.city }; lbxq2.itemssource = q2; } 
if you're looking more fluent syntax... use this:
string selectedcity = (string)cmbq2.selectedvalue; var query = db.addresses.where(address => address.city == selectedcity) .selectmany(address => address.customeraddresses) .select(customeraddress => new { name = customeraddress.customer.firstname, city = customeraddress.address.city }); the class customeraddress need have navigation property referencing customer class , navigation property address, you'll need collection of customeraddress navigation property on address, e.g. icollection<customeraddress>.
in addition that, migrate of code separate project. ever user interacts site, layer presentation layer concern, whether app developed using winforms, wpf or asp.net, project should deal issues concerning user experience, presentation of data exposes , validation concerning input values, error messages etc.
the data access logic, logic you've written above should in separate one... presentation layer can request content from.
i highly recommend begin n-tier architecture structuring applications correctly.
i recommend using entity framework.
Comments
Post a Comment