It is not very clear to me why I am not able to get the number of rows returned using linq-to-sql
I had this query to use as validation:
var obj1 = (from c in context.sistema_DocType_Index
where c.indexId == id
select c).First();
if(obj1 != null) {}
I was getting a null exception using First() method if there was no row returned. Ok, so I decided to use Count().
var obj1 = (from c in context.sistema_DocType_Index
where c.indexId == id
select c).Count();
if(obj1 > 0) {}
I have 3 rows returning from the database but the Count() gives me 0.
Why is that?
you can use
Any();method. which is the best use for this case. Any()