-
Notifications
You must be signed in to change notification settings - Fork 387
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
Scaffolding doesn't include tinyint(3) unsigned column in the map #655
Comments
Byte maps to tinyint unsigned. Were you expecting HasColumnType with display width? |
I was expecting .Property() entry with or without HasColumnType(). |
It appears that this is caused by the fix for #394 which strips out the display width for unsigned integers. |
This was very likely fixed by #896. I will check this later at some point. |
I can confirm that this is fixed now in I ran the following SQL: CREATE TABLE `Issue655`.`IceCream` (
`Id` INT NOT NULL AUTO_INCREMENT,
`WeightInGrams` TINYINT(3) UNSIGNED NOT NULL,
PRIMARY KEY (`Id`)
); Then i scaffolded the database: dotnet ef dbcontext scaffold "server=127.0.0.1;user id=root;password=;port=3306;database=Issue655" Pomelo.EntityFrameworkCore.MySql -c Context The following classes were generated: public partial class IceCream
{
public int Id { get; set; }
public byte WeightInGrams { get; set; } // <-- correct CLR type
}
public partial class Context : DbContext
{
public Context()
{
}
public Context(DbContextOptions<Context> options)
: base(options)
{
}
public virtual DbSet<IceCream> IceCream { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
optionsBuilder.UseMySql(
"server=127.0.0.1;user id=root;password=;port=3306;database=Issue655");
}
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<IceCream>(entity =>
{
entity.Property(e => e.Id)
.HasColumnType("int(11)");
entity.Property(e => e.WeightInGrams)
.HasColumnType("tinyint(3) unsigned"); // <-- correct MySQL type
});
OnModelCreatingPartial(modelBuilder);
}
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
} Finally, the following test executed successfully: internal class Program
{
private static void Main()
{
using var context = new Context();
context.Database.EnsureDeleted();
context.Database.EnsureCreated();
context.IceCream.Add(new IceCream { WeightInGrams = 68 });
context.SaveChanges();
var iceCream = context.IceCream.Single();
Debug.Assert(iceCream.WeightInGrams is byte);
Debug.Assert(iceCream.WeightInGrams == 68);
}
} |
Steps to reproduce
Have a table with
tinyint(3) unsigned
column, run scaffolding.The issue
The entity is generated correctly and includes property of type byte, however the property is missing from the entity's map in DbContext.OnModelCreating()
Further technical details
MySQL version: 8.0.11
Operating system: Win 7 x64
Pomelo.EntityFrameworkCore.MySql version: 2.1.1
The text was updated successfully, but these errors were encountered: