check if record exist

  • Thread starter Thread starter Seema
  • Start date Start date
S

Seema

What is the best way to check for a record exists in a database using linq to
sql?
I want to check if a userid (int) and typeid (int) exist. - The following
code always returns zero even if the record exists - what is the best
approach?

int result = 0
result = (from t in context.customers
where ((t.userid == intUserID) && (t.typeid ==
intTypeID))
select t).Count();
 
What is the best way to check for a record exists in a database using linq to
sql?
I want to check if a userid (int) and typeid (int)  exist. - The following
code always returns zero even if the record exists - what is the best
approach?

int result = 0
result = (from t in context.customers
                              where ((t.userid == intUserID) && (t.typeid ==
 intTypeID))
                              select t).Count();

var v = from t in context.customers where t.userid == intUserID &&
t.typeid == intTypeID select t;
bool exists = v.Count() == 0 ? false : true;
 
Back
Top