check if record exist

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();
 
G

Guest

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;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top