-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
The expected type was 'System.Nullable`1[System.Boolean]' but the actual value was of type 'System.Int32 #11516
Comments
@sepehr1014 Can you share also your model? |
@sepehr1014 yes, it would really help if you can provide a repro project. |
@ilmax @divega Sorry for the delay. The model is pretty normal & it doesn't even map to a table. It's just a query model (not specified as such in the context's OnModelCreating though) private class FriendModel
{
public string Id { get; set; }
public string FullName { get; set; }
public string Picture { get; set; }
public DateTime? LastOnlineDate { get; set; }
public string UserName { get; set; }
public bool CanSeeOnlineStatus { get; set; }
} |
I could not reproduce the issue. I used the following repro: using (var ctx = new MyContext())
{
ctx.Database.EnsureDeleted();
ctx.Database.EnsureCreated();
var f1 = new UserEntity
{
OnlineShownToContacts = true,
OnlineShownToEveryone = true,
OnlineShownToFollowers = true,
OnlineShownToFollowings = true,
PhoneNumber = "12345"
};
var f2 = new UserEntity
{
OnlineShownToContacts = false,
OnlineShownToEveryone = false,
OnlineShownToFollowers = false,
OnlineShownToFollowings = false,
PhoneNumber = "54321"
};
ctx.Friends.AddRange(f1, f2);
ctx.SaveChanges();
ctx.Database.EnsureCreated();
}
using (var db = new MyContext())
{
var myCount = 2;
var currentUser = new UserEntity
{
Id = 1,
OnlineShownToContacts = true,
OnlineShownToEveryone = true,
OnlineShownToFollowers = true,
OnlineShownToFollowings = true,
PhoneNumber = "12345"
};
var query = db.Friends.Select(u => new MyModel
{
CanSeeOnlineStatus = (
currentUser.OnlineShownToEveryone ||
(currentUser.OnlineShownToContacts && db.UserContactNumbers.Any(n => n.User_Id == currentUser.Id && n.Number == u.PhoneNumber)) ||
(currentUser.OnlineShownToFollowings && db.UserFollowers.Any(f => f.Follower_Id == currentUser.Id && f.User_Id == u.Id)) ||
(currentUser.OnlineShownToFollowers && db.UserFollowers.Any(f => f.Follower_Id == u.Id && f.User_Id == currentUser.Id))
) && (
u.OnlineShownToEveryone ||
(u.OnlineShownToContacts && db.UserContactNumbers.Any(n => n.User_Id == u.Id && n.Number == currentUser.PhoneNumber)) ||
(u.OnlineShownToFollowings && db.UserFollowers.Any(f => f.Follower_Id == u.Id && f.User_Id == currentUser.Id)) ||
(u.OnlineShownToFollowers && db.UserFollowers.Any(f => f.Follower_Id == currentUser.Id && f.User_Id == u.Id))
)
}).Take(myCount).ToArray();
}
public class MyModel
{
public bool? CanSeeOnlineStatus { get; set; }
}
public class UserEntity
{
public int Id { get; set; }
public bool OnlineShownToEveryone { get; set; }
public bool OnlineShownToContacts { get; set; }
public bool OnlineShownToFollowings { get; set; }
public string PhoneNumber { get; set; }
public bool OnlineShownToFollowers { get; set; }
}
public class MyContext : DbContext
{
public DbSet<UserEntity> Friends { get; set; }
public DbSet<UserFollower> UserFollowers { get; set; }
public DbSet<UserContactNumber> UserContactNumbers { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=Repro11516;Trusted_Connection=True;MultipleActiveResultSets=True");
}
}
public class UserFollower
{
public int Id { get; set; }
public int Follower_Id { get; set; }
public int User_Id { get; set; }
}
public class UserContactNumber
{
public int Id { get; set; }
public int User_Id { get; set; }
public string Number { get; set; }
}
public class FriendModel
{
public string Id { get; set; }
public string FullName { get; set; }
public string Picture { get; set; }
public DateTime? LastOnlineDate { get; set; }
public string UserName { get; set; }
public bool CanSeeOnlineStatus { get; set; }
} @sepehr1014 please modify the code above so that it reproduces the problem you are seeing and re-open the issue. This issue could already be fixed by a recent commit: 3902d94, although I tested the repro above on a code that didn't have the fix yet. |
@maumar Thank you for following up on this matter. I will test and try to reproduce this error. BTW we're using memory optimized tables which are not created by EF. Does that make any difference regarding this issue? |
@sepehr1014 - Memory optimized table should not make any difference when it comes to query. It only affects DDL & update SQLs. |
I'm seeing a similar error on 2.1.0-preview2-final. Did not see this on preview1.
From a simple query looking like this:
|
Rewriting to this fixed the issue for me:
But that should not be necessary. |
Should be fixed by #12280 |
It seems there's a serious issue in the translation of this query:
Steps to reproduce
Use the above query. It should return bool but returns int instead.
Further technical details
EF Core version: 2.1.0-preview1-final
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows Server 2016
Using in-memory tables in SQL Server 2017
The text was updated successfully, but these errors were encountered: