我是LINQ的新手。我有一个GridView,我使用LINQ填充。我的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是一种字符串。我该如何将此QS转换为整数?谢谢!
答案 0 :(得分:3)
确保使用== not =并使用“getEntity”变量的int版本。
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();
}
答案 1 :(得分:2)
您应该使用解析后的整数值:
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!
};
答案 2 :(得分:0)
好!这是:
我在Entity表中的ID是PK,而User Table中的EntityID是一种int但没有约束。 所以这是
1-MANY Relationship。