1

I am executing following query. I am doing this in aspnetzero framework and doing this in UserAppService.cs file.

var rt = _dbContextProvider.GetDbContext().Users
                    .Where(e => e.Id == 11)
                    .FirstOrDefault();

But this is always returning null, in database there is record with Id = 11.

So anyone has any idea what is wrong in this.

Thanks

Samif
  • 57
  • 8
  • Chances are your application is using a connection string to a database you aren't expecting. Check the value of `_dbContextProvider.GetDbContext().Database.Connection.ConnectionString` to verify that it is connecting to the same database server/instance you are inspecting for records. Also check that your context hasn't added alternate tables based on the naming convention. (I.e. under default namespace or pluralized class name) – Steve Py Dec 06 '20 at 22:35
  • 2
    Try to add `.IgnoreQueryFilters()`, probably you have defined query filters. – Svyatoslav Danyliv Dec 06 '20 at 23:08

1 Answers1

1

As Svyatoslav Danyliv said in the comment, the issue is related to the query filters, try to add the .IgnoreQueryFilters() to ignore the query filters.

Zhi Lv
  • 18,845
  • 1
  • 19
  • 30