zompinc / efcore-extensions

Provides window (analytics) functions and binary functions for EF Core. Providers: SQL Server, SQLite, Postgres.
MIT License
66 stars 6 forks source link

Using EF.Functions.Count without arguments (`COUNT(*)`) #18

Closed InspiringCode closed 8 months ago

InspiringCode commented 8 months ago

Is there any way I could write a query that results in SELECT X, COUNT(*) OVER() TotalCount FROM y?

I tried EF.Functions(1, EF.Functions.Over()) and EF.Functions(new { One = 1 }, EF.Functions.Over()) and a few other variants but they all throw an exception. Would it be possible to provide an overload of Count that takes no query parameters and just produces COUNT(*) in this case?

virzak commented 8 months ago

Yeah, should be able to do that soon. In the meantime you can insert any non nullable column. If all your columns are nullable you can do this;

var query = DbContext.TestRows
.Select(r => EF.Functions.Count<int, TResult>(r.Col1 == null ? 1 : 1, EF.Functions.Over()));
virzak commented 8 months ago

@InspiringCode, this is available starting version 8.0.18-beta