Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Join在LINQ语句中不起作用_C#_Asp.net_Linq To Sql_Web Applications - Fatal编程技术网

C# Join在LINQ语句中不起作用

C# Join在LINQ语句中不起作用,c#,asp.net,linq-to-sql,web-applications,C#,Asp.net,Linq To Sql,Web Applications,我是LINQ的新手。我有一个使用LINQ填充的GridView。我的LINQ语句从上一页获取查询字符串。查询字符串采用字符串格式。代码如下: protected void Page_Load(object sender, EventArgs e) { string getEntity = Request.QueryString["EntityID"]; int getIntEntity = Int32.Parse(getEntity);

我是LINQ的新手。我有一个使用LINQ填充的GridView。我的LINQ语句从上一页获取查询字符串。查询字符串采用字符串格式。代码如下:

 protected void Page_Load(object sender, EventArgs e)
    {
        string getEntity = Request.QueryString["EntityID"];
        int getIntEntity = Int32.Parse(getEntity);
        OISLinqtoSQLDataContext db = new OISLinqtoSQLDataContext();
        var tr = from r in db.Users
                 join s in db.Entities on r.UserID equals s.ID
                 where s.ID = Request.QueryString["EntityID"]
                 select new
                 {
                     //To Show Items in GridView!
                 };

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

    }

s、 ID不等于QueryString。S.ID是int类型,QS是string类型。我应该如何将这个QS转换成整数?谢谢大家!

您应该使用解析后的整数值:

 var tr = from r in db.Users
             join s in db.Entities on r.UserID equals s.ID
             where s.ID == getIntEntity
             select new
             {
                 //To Show Items in GridView!
             };

确保使用==not=并使用int版本的“getEntity”变量

protected void Page_Load(object sender, EventArgs e)
{
    string getEntity = Request.QueryString["EntityID"];
    int getIntEntity = Int32.Parse(getEntity);
    OISLinqtoSQLDataContext db = new OISLinqtoSQLDataContext();
    var tr = from r in db.Users
             join s in db.Entities on r.UserID equals s.ID
             where s.ID == getIntEntity
             select new
             {
                 //To Show Items in GridView!
             };

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

}
好的!这是:

实体表中我的ID是PK,用户表中的EntityID是int类型,但没有约束。 所以这是

一对多的关系


您已经将查询字符串转换为int-
getIntEntity
。在你的查询中使用这个,是的,凯文。但是在我的JOIN中有一个错误显示:error JOIN子句中某个表达式的类型不正确。调用“Join”时类型推断失败。是的,确实如此。但是在我的JOIN中有一个错误显示:error JOIN子句中某个表达式的类型不正确。调用“Join”时类型推断失败。@klm9971:db.Entities.ID和db.Users.UserID的类型是什么?