2
DataClassesDataContext MyDB = new DataClassesDataContext();
var id = from wineT in MyDB.Wineries
         where wineT.wineryID==Convert.ToInt32(
             from w in MyDB.WineTypes
             where w.kind==ddlSorti.SelectedItem.Text
             select w.wineryID)
         select  wineT.name;

GridView1.DataSource = id;
GridView1.DataBind();

我有这段代码,我没有任何错误,但是当我启动应用程序时,我收到这个错误“无法格式化节点'ClientQuery'以作为 SQL 执行”。

4

1 回答 1

1

您需要FirstOrDefault()在子选择中添加

var id = from wineT in MyDB.Wineries
         where wineT.wineryID==Convert.ToInt32(
             from w in MyDB.WineTypes
             where w.kind==ddlSorti.SelectedItem.Text
             select w.wineryID).FirstOrDefault()
         select  wineT.name;
于 2012-07-23T13:25:25.927 回答