-
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
Entity Class with Enum : long property does not translate into BigInt when using Enum.HasFlag #8538
Comments
@rcyq What is the type of the database column? |
@rcyq Also, can you post the SQL that is generated? Or provide a full code listing or project to reproduce what you are seeing? |
The following migration is created after running migrationBuilder.CreateTable(
name: "Assignments",
columns: table => new
{
Id = table.Column<long>(nullable: false)
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
Permissions = table.Column<long>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Assignments", x => x.Id);
}); The sql script generated as follows (using CREATE TABLE [Assignments] (
[Id] bigint NOT NULL IDENTITY,
[Permissions] bigint NOT NULL
);
GO |
I created a sample project which replicates the issue above, Ef Core Sample You can head over to the "Courses" tab when running the web application which the issue will occur. |
I have the same issue. Can't find any magic dust to get around it. // My world
My object model is decorated like so:
I've tried building my query several different ways and eventually I ended up passing a raw T-SQL statement like this and got the same results. The same error is caused when using a simple Linq Where clause and Pete Montgomery's PredicateBuilder. // Shortened for brevity - this is all you should need to duplicate the exception This also produces the same error: I've tried casting the 'requiredFlags' parameter and even the raw value '0x0008000000000000' to a 'numeric' and decimal but Microsoft.EntityFrameworkCore tries to convert it to a numeric every time. The actual exception is: "System.Data.SqlClient.SqlException: The data types bigint and numeric are incompatible in the '&' operator." This expression is being converted in EntityFrameworkCore. Please note that this same way of building our expression has been in production for five years. The same code works perfect in TSQL also. This error has manifested itself only after upgrading our code to EntityFrameworkCore. The exception is thrown in a 'NetStandard 1.4' module (DLL) Environment
BTW: I've tested just the netstandard 1.4 module with a test console application and it produces the same error. Thanks for your help and any suggestions or work around. |
Update: I found the magic dust for at least a temporary solution.... It seams like Linq to Entities doesn't like Int64. Rather then converting it to a long it converts it to a numeric during a query. When I define my flags as follows (with an Int64) my query produces the exception
But when I define my flags like this - my query works as expected.
Hope this helps someone. |
When a linq to entities query is constructed with an Any clause which compare an entity property of
Enum : long
against a constant ofEnum : long
, the entity property does not translate into BigInt.Steps to reproduce
Create an entity class as follows:
Create an enum as follows:
Construct a query to check for FULL_ACCESS_ALL
The code above thrown the exception stated in the stacktrace.
However, when comparing in the following code, no exception was thrown:
Also, when comparing the entity property against the enum field in the same enum class but with value < 32 bits, no exception was thrown as well.
EF Core version: 1.1.2
Database Provider: Microsoft.EntityFrameworkCore.SqlServer 1.1.2
Operating system:
IDE: Visual Studio 2017
The text was updated successfully, but these errors were encountered: