我有 2 个表:winery 和 wineType(在 wineType 中我有酒厂的外键,称为 wineryID)。我尝试获取所有生产葡萄酒的酒厂名称,例如客户从下拉列表中选择的酒厂名称。我有这个功能
public void ispolniLista()
{
DataClassesDataContext MyDB = new DataClassesDataContext();
var id = from wineT in MyDB.WineTypes where wineT.kind == ddlSorti.SelectedItem.Text select new { wineT.wineryID };
List<int> listaID = id as List<int>;
List<string> listaIminja = new List<string>();
try
{
foreach (int i in listaID)
{
var vname = from w in MyDB.Wineries where w.wineryID == i select new { w.name };
listaIminja.Add(vname.ToString());
}
lstVinarii.DataSource = listaIminja;
lstVinarii.DataBind();
}
catch (NullReferenceException err)
{
Console.Write(err.Message);
}
}
我没有任何结果,lstVinarii 是空的。