Join is not working in LINQ statement
I am new to LINQ. I have a GridView which I am populating using LINQ. My LINQ statement is taking query string from previous page. The query string is in string format. Here is the code:
protected void Page_Load(object sender, EventArgs e)
{
string getEntity = Request.QueryStrin开发者_JAVA技巧g["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 is not equal to QueryString. S.ID is a type of int and QS is a type of string. How should I convert this QS into an integer? Thank you!
Make sure you are using == not = and use the int version of the "getEntity" variable.
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();
}
You should use your parsed integer value instead:
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!
};
Okay! Here it is:
My ID in Entity table is PK and EntityID in User Table is a type of int but no constraints. So this is
1-MANY Relationship.
精彩评论