Linq-to-sql code does not return results, even though

I have the following code in the application

var query = context.xosAssets.Where(x => x.GSA == 0).Take(INDEX_ASSET_QUERY_COUNT); var assets = query.ToList(); // Debug string message = string.Format("Assets waiting for indexing: {1}{0}Database:{3}{0}Query: {2}", Environment.NewLine, query.Count(), query.ToString(), context.Connection.Database); System.Diagnostics.EventLog.WriteEntry("GSAFeed", message, System.Diagnostics.EventLogEntryType.Information); 

When this is done, query.Count() is zero, and assets.Count is zero because the results are not returned. However, this is not true, since ALL records in this database have a GSA field set to zero.

When I take the output from query.ToString() and run it (replacing @p0 with 0), I get all the correct answers. I checked that I am "in the same database that displays context.Connection.Database , and I am running out of options, which may be incorrect.

Why doesn't Linq-to-sql return any results even if the actual sql does?

+4
source share
1 answer

In the past, I came across problems as usual, I basically rewrote Linq2Sql in a long form, and this caused me problems. Not an expert enough to know why, but it might help you.

EDIT Something like this:

 var query = (from x in context.xosAssets where x.GSA == 0 select x).Take(INDEX_ASSET_QUERY_COUNT); 

This should return IQueryable, so no .ToLIst () need to be done.

0
source

Source: https://habr.com/ru/post/1400605/


All Articles