Function Accessing UD table not responding properly

I have the following code in a function. The goal is to check to see if a record exists in the UD table. I have it writing some statements out to a file as part of my debug process. When I execute this code I see the before if and after if messages but I don’t get the found something one. It acts like it returns something (so it is not null) but then there is nothing there? What am I missing?


var ttester = Db.UD33.Where(o=>o.Company == Session.CompanyID && o.Key2 == jpJobNum && o.Date01 == jpDate);

sw.WriteLine(“before if”);

if (ttester != null)
{
    sw.WriteLine(“after if”);
    // foreach (var tt in ttester)
    if (ttester.Any())
    {
        sw.WriteLine(“found something” );
    }
}


If you are just seeing if there is a record you could just try and do a count?


int cnt = Db.UD33.Count(o =>
    o.Company == Session.CompanyID &&
    o.Key2 == jpJobNum &&
    o.Date01 == jpDate);

sw.WriteLine($“found {cnt} rows”);

if (cnt > 0)
{
    sw.WriteLine(“found something”);
}

Thanks! It says it is returning 0 rows. I will use that instead of the other logic I was using.

Still not sure why it returns as not null. Oh well.

Because that returns an IQueryable or IEnumerable. It’s an object with 0 rows, but the object itself is not null.