Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.Nullable Boolean cannot be used for parameter of type System.Boolean #4753

Closed
capesean opened this issue Mar 10, 2016 · 2 comments
Closed
Assignees
Labels

Comments

@capesean
Copy link

The below repro gives the error:

System.Func'2[Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor+TransparentIdentifier'2[Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor+TransparentIdentifier'2[efinmemory.Time,System.Collections.Generic.IEnumerable'1[efinmemory.Invoice]],efinmemory.Invoice],System.Nullable'1[System.Boolean]]' cannot be used for parameter of type 'System.Func'2[Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor+TransparentIdentifier'2[Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor+TransparentIdentifier'2[efinmemory.Time,System.Collections.Generic.IEnumerable'1[efinmemory.Invoice]],efinmemory.Invoice],System.Boolean]' of method 'System.Collections.Generic.IEnumerable'1[Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor+TransparentIdentifier'2[Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor+TransparentIdentifier'2[efinmemory.Time,System.Collections.Generic.IEnumerable'1[efinmemory.Invoice]],efinmemory.Invoice]] _Where[TransparentIdentifier'2](System.Collections.Generic.IEnumerable'1[Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor+TransparentIdentifier'2[Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor+TransparentIdentifier'2[efinmemory.Time,System.Collections.Generic.IEnumerable'1[efinmemory.Invoice]],efinmemory.Invoice]], System.Func'2[Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor+TransparentIdentifier'2[Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor+TransparentIdentifier'2[efinmemory.Time,System.Collections.Generic.IEnumerable'1[efinmemory.Invoice]],efinmemory.Invoice],System.Boolean])'

Here is the code sample: I'm just trying to get the sum of the time amounts on times that have been invoiced, where the invoice is billable.

using Microsoft.EntityFrameworkCore;
using System;
using System.ComponentModel.DataAnnotations;
using System.Linq;

namespace efinmemory
{
    public class Program
    {
        public static void Main(string[] args)
        {
            using (var db = new DBContext())
            {
                var result = db.Times.Where(t => t.InvoiceId.HasValue && t.Invoice.IsBillable).Sum(t => t.Amount);
                Console.WriteLine($"RESULT: {result}");

            }

            Console.ReadKey();
        }
    }

    public class DBContext : DbContext
    {
        public DbSet<Invoice> Invoices { get; set; }
        public DbSet<Time> Times { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseInMemoryDatabase();
            base.OnConfiguring(optionsBuilder);
        }
    }

    public class Invoice
    {
        [Key]
        public int InvoiceId { get; set; }
        public bool IsBillable { get; set; }
    }

    public class Time
    {
        [Key]
        public int TimeId { get; set; }
        public int? InvoiceId { get; set; }
        public virtual Invoice Invoice { get; set; }
        public decimal Amount { get; set; }
    }

}
@maumar
Copy link
Contributor

maumar commented Mar 29, 2016

This is still broken. However there is a simple workaround:

var result = db.Times
    .Where(t => t.InvoiceId.HasValue && t.Invoice.IsBillable == true)
    .Sum(t => t.Amount);

@maumar
Copy link
Contributor

maumar commented May 26, 2016

closing this one, since we got a similar bug with some more context (#5454)

@maumar maumar closed this as completed May 26, 2016
@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants