When using alongside a modelBuilder.HasDbFunction() throws `Non-static method requires a target`
I added a DB fucntion:
modelBuilder.HasDbFunction(
typeof(DateTimeExtensions).GetMethod(nameof(DateTimeExtensions.MonthsDeltaFractionalDb),
new[] { typeof(DateTimeOffset), typeof(DateTimeOffset) })!)
.HasName("months_delta_fractional");
And am using it in a query:
BudgetDetailsResponse? budget = await _dbContext.Companies
.Include(x => x.Orders)
.Include(x => x.Campaigns)
.Where(x => x.Id == companyId)
.Select(x => new BudgetDetailsResponse
{
UsedBudget = x.Orders!
.ExcludeOptionalOrder(excludeOrderId)
.Where(order => Order.UsedBudgetStatuses.Contains(order.Status))
.Sum(order => order.TotalPrice / order.FlightTimeMonths),
}).FirstOrDefaultAsync();
With an entity configured as so:
public double FlightTimeMonths => DateTimeExtensions.MonthsDeltaFractionalDb(StartDate, EndDate);
[Projectable]
public int FlightTimeDays => (EndDate - StartDate).Days;
[Projectable]
public double AvgPlaysPerDay => FlightTimeMonths * PlaysPerMonth / FlightTimeDays;
[Projectable]
public double TotalPlays => AvgPlaysPerDay * FlightTimeDays;
[Projectable]
public double TotalPrice => Pricing.GetTotalPrice((int)Math.Round(TotalPlays));
It seems that the use of a DBFunction and a projectable together creates a problem?
Can you clarify what is not working?
https://github.com/koenbeuk/EntityFrameworkCore.Projectables/blob/issue/123/tests/EntityFrameworkCore.Projectables.FunctionalTests/DbFunctionTests.cs translates just fine.
thanks for the response!
When I use the above, queries throw the exception:
Non-static method requires a target
If I remove the HasDbFunction, stop projecting, or stop using projectable proeprties, the problem goes away.
I'll see if I can find the differences in the setup from what you linked to. It may take me a bit to circle back around,