Skip to content

When using alongside a modelBuilder.HasDbFunction() throws Non-static method requires a target #123

@douglasg14b

Description

@douglasg14b

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions