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

[MySql/MariaDb] Insert an boolean type has invalid result (Always insert true in a bit column) #1521

Closed
Cyril12740 opened this issue Jun 24, 2024 · 3 comments

Comments

@Cyril12740
Copy link

Cyril12740 commented Jun 24, 2024

Hi,

With the following code, i have 2 different behaviours when the column's type is bit or tiny(1).

var items = new List<ConsoleApp1.BooleanBulkInsertDbContext.TestClass>()
{
    new()
    {
        Name = "Is active is true",
        IsActive = true,
    },
    new()
    {
        Name = "Is active is false",
        IsActive = false,
    }
};


DbContext context = GetDbContext();

context.BulkInsert(items);

When the column's type is tinyint(1), the inserted result is :
image

When the column's type is bit, the inserted result is :
image

@borisdj
Copy link
Owner

borisdj commented Aug 15, 2024

Unable to reproduce it.
I have added in Test InsertTestMySql in entity 2 new columns:

public bool IsActiveFirst { get; set; } // in db becomes TINYINT(1) by default

[Column(TypeName = "BIT")]
public bool IsActiveSecond { get; set; } // in db becomes BIT(1)

Then in test set:
IsActiveFirst = i % 2 == 0 ? true : false,
IsActiveSecond = i % 2 == 0 ? true : false,

In db first 4 rows are:
1 __ 0 __ 0
2 __ 1 __ 1
3 __ 0 __ 0
4 __ 1 __ 1
...

@borisdj
Copy link
Owner

borisdj commented Aug 15, 2024

Closing this for now, if you manage to make it reproducible, write it here and will reopen.

@borisdj borisdj closed this as completed Aug 15, 2024
@chasse20
Copy link

chasse20 commented Aug 19, 2024

Open this back up please. This is reproduceable and always outputs 1 even if the DTO's bool was set to false.

MySQL: 8.0.25
EFCore.BulkExtensions: 8.1.0
EFCore: 8.0.8

DTO:

public class DailyOption
{
	public int DailyOptionId { get; set; }
	public DateOnly Time { get; set; }
	public bool IsCall { get; set; }
}

Database Table:

CREATE TABLE `DailyOption` (
  `DailyOptionId` int NOT NULL AUTO_INCREMENT,
  `Time` date NOT NULL,
  `IsCall` bit(1) NOT NULL,
  PRIMARY KEY (`DailyOptionId`),
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants