How to get Count from FromSql?

c# ef-core-2.1 entity-framework-core sql-server

Question

I have

dbContext.Items.FromSql("SELECT COUNT(*) 
                         FROM Items 
                         WHERE JSON_VALUE(Column, '$.json') = 'abc'")

This returns an IQueryable, I am wondering how I can return a scalar int back?

1
2
11/6/2018 9:46:29 PM

Popular Answer

Try

 var firstElement = dbContext.Items
                             .FromSql (..)
                             .ToList
                             .First();
1
11/6/2018 8:27:27 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow