x.CityID无效,如何编写lambda表达式?
private void adressComboBoxFill<T>(MetroComboBox varComboBox, System.Data.Entity.DbSet<T> dbSet, string place) where T : class
{
if (place == "City"){
varComboBox.DataSource = dbSet.ToList();
}
else if (place == "District"){
var type = dbSet.GetType();
varComboBox.DataSource = dbSet.Where(x => x.CityID == selectedCity.CityID).ToList();
}
varComboBox.DisplayMember = place + "Name";
varComboBox.ValueMember = place + "ID";
}
您需要将以下行更改为
varComboBox.DataSource = dbSet.Cities.Where(x => x.CityID == selectedCity.CityID).ToList();
它是无效的,因为您在DBSet T中传递了一个泛型参数。它对曼城一无所知。
你需要使它不通用DB城市集或其他什么。