嗨我在实体框架上太新了,我在windows form app上使用它。
using (GezentiEntities GE = new GezentiEntities())
{
var cities = from c in GE.Cities
where c.CountryId == ((Guid)(dgCountry.SelectedRows[0].Cells[0].Value))
select new { c.Id, Şehir = c.Name };
dgCity.DataSource = cities.ToList();
}
on dgCity.DataSource = cities.ToList();当我使用where where条件和((Guid)(dgCountry.SelectedRows [0] .Cells [0] .Value))时,它给了我错误,该代码工作得很好,它给了我ID。
答案 0 :(得分:0)
您可以尝试从linq到实体查询中获取所需的ID
var id = (Guid)dgCountry.SelectedRows[0].Cells[0].Value;
var cities = from c in GE.Cities
where c.CountryId == id
select new { c.Id, Şehir = c.Name };
dgCity.DataSource = cities.ToList();