-
-
Notifications
You must be signed in to change notification settings - Fork 390
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
NRE when adding migrations to version 6.0.0-preview.5 #1491
Comments
If you're using .NET5 you should be using Pomelo 5.0.1 which is the latest stable release. You haven't provided the models for either Also see Entity Framework Core 2.1 Add Migration System.NullReferenceException for some steps to try, |
Ok I'll try version 5.0.1 On the current issue. public class RegistryOrderServices
{
public Guid Id { get; set; }
public RegistryOrderServicesType Type { get; set; }
public double Count { get; set; }
public decimal Price { get; set; }
public Guid RegistryOrderId { get; set; }
public RegistryOrder RegistryOrder { get; set; }
}
public class WaybillAutocompleteRule
{
public Guid Id { get; set; }
public string Key { get; set; }
public WaybillAutocompleteRuleType Type { get; set; }
public IEnumerable<string> Values { get; set; }
public Guid AutocompleteId { get; set; }
public WaybillAutocomplete Autocomplete { get; set; }
} DBContext: public class Store : MigratorDbContext
{
public Store(DbContextOptions options) : base(options) { }
public DbSet<RegistryOrderServices> RegistryOrderServices { get; set; }
public DbSet<WaybillAutocompleteRule> WaybillAutocompleteRules { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.ApplyConfigurationsFromAssembly(typeof(Store).Assembly);
}
public override void Dispose()
{
base.Dispose();
}
}
public abstract class MigratorDbContext : DbContext
{
public MigratorDbContext(DbContextOptions options) : base(options) { }
public DbSet<MigrationEntity> Migrations { get; set; }
} Other DbSets are irrelevant (I will be punished for posting the full text). Stack trace:
I tried the method provided by the link on SO, did not help, I get the same error. |
What code is in lines 1012 and 1018 of StoreModelSnapshot.cs? Also see EF Core 2.1 project Add-Migration NullReferenceException. |
Pomelo In addition to what @mguinness said, please post your Fluent API configuration for the Also make sure that your
|
I tried this method and it did not help, I get the same error. On version 5.0.1, everything works well, migrations are added and removed without errors. |
public class RegistryOrderServicesConfig : IEntityTypeConfiguration<RegistryOrderServices>
{
public void Configure(EntityTypeBuilder<RegistryOrderServices> builder)
{
builder.ToTable("registry_order_services");
builder.HasKey(e => e.Id);
builder.Property(e => e.Type).IsRequired();
builder.Property(e => e.RegistryOrderId).IsRequired();
}
}
public class WaybillAutocompleteRuleConfig : IEntityTypeConfiguration<WaybillAutocompleteRule>
{
public void Configure(EntityTypeBuilder<WaybillAutocompleteRule> builder)
{
builder.ToTable("waybill_autocomplete_rules");
builder.Property(e => e.Key).IsRequired();
builder.Property(e => e.Type).IsRequired();
builder.Property(e => e.Values).IsRequired();
builder.HasOne(e => e.Autocomplete)
.WithMany(e => e.Rules)
.HasForeignKey(e => e.AutocompleteId)
.IsRequired();
builder.Property(e => e.Values)
.HasConversion(x => string.Join(';', x), x => x.Split(';', StringSplitOptions.None));
}
}
Entity Framework Core .NET Command-line Tools The .cproj file contains a preview version: |
@war-beast I am able to reproduce this. This seems to be a bug in EF Core that is only triggered for specific entity property names (e.g. when your property is named The underlying issue seems to be, that EF Core is checking the properties of the wrong type. It does enumerated the properties of the This is the line with the issue: memberInfo ??= Metadata.ClrType.GetMembersInHierarchy(propertyName).FirstOrDefault(); @AndriySvyryd, @ajcvickers Reproduced with the following code: Program.csusing System;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
namespace IssueConsoleTemplate
{
public class RegistryOrderServices
{
public Guid Id { get; set; }
public double Count { get; set; }
}
public class Context : DbContext
{
public DbSet<RegistryOrderServices> RegistryOrderServices { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
var connectionString = "server=127.0.0.1;port=3308;user=root;password=;database=Issue1491";
var serverVersion = ServerVersion.AutoDetect(connectionString);
optionsBuilder.UseMySql(connectionString, serverVersion)
.UseLoggerFactory(
LoggerFactory.Create(
b => b
.AddConsole()
.AddFilter(level => level >= LogLevel.Information)))
.EnableSensitiveDataLogging()
.EnableDetailedErrors();
}
}
}
internal static class Program
{
private static void Main()
{
}
}
} Add an initial migration and then another one (can be empty). @war-beast If you want to use the previews, then the quickes workaround is probably to just rename your property to something different than |
@lauxjpn thank you ever so much!
It will be difficult to do, too much of everything is tied to this data. I will wait for the solution of this issue.
As I understand it, does the same thing happen with a property named "Values"? |
I would expect it to suffer from the same issue. |
This has been fixed in EF Core upstream and will be part of EF Core 6.0 RC2. |
We have migrated our project from Core 2.2 to .NET5. We also updated Pomelo.EntityFrameworkCore.MySql to version 6.0.0-preview.5
When adding a migration, whether it is empty or with changes to the database model, the exception
Object reference not set to an instance of an object.
in 2 places in the file inherited from ModelSnapshot:b.Property<string[]>("Values")
There is a transformation in the configuration of this property:
builder.Property(e => e.Values).HasConversion(x => string.Join(';', x), x => x.Split(';', StringSplitOptions.None));
The second place of the same exception, in the line with
b.Property<double>("Count")
In the model, the type of the Values property is
IEnumerable<string>
(but the database stores a string separated by ";") and the type of the Count property is double.If I delete the ModelSnapshot file and add a migration, a new snapshot file is generated and the migration is created, with exactly the same lines. But when I try to delete this migration or add 1 more, I get exactly the same exceptions.
The text was updated successfully, but these errors were encountered: