Check one value in two tables using LINQ

Posted by Mandlaa under ASP.NET MVC on 5/19/2014 | Points: 10 | Views : 527 | Status : [Member] | Replies : 1
This is my code for check value in one table

var Tagid = collection["TagNo"];

var qry = (from c1 in db.Table1 where c1.TagNo.ToString() ==Tagid select c1).Count();
if (qry != 1)
{
//Some code
}


I want to check same value in two tables how can i check?
modify my query




Responses

Posted by: kgovindarao523-21772 on: 5/20/2014 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi,
Try like this.

var Tagid = collection["TagNo"];           
var qry = (from c1 in db.Table1
from c2 in db.Table2
where c1.TagNo.ToString() == Tagid && c2.TagNo.ToString() == Tagid
select c1).Count();

if (qry != 1)
{

//Some code

}


Thank you,
Govind

Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response