-
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
EF Core Cosmos 7.0.13 => 7.0.14 Value cannot be null. (Parameter 'derivedType') #32363
Comments
@PiotrKadziewicz I am not able to reproduce this--see my code below. Please attach a small, runnable project or post a small, runnable code listing that reproduces what you are seeing so that we can investigate. using (var context = new SomeDbContext())
{
await context.Database.EnsureDeletedAsync();
await context.Database.EnsureCreatedAsync();
context.Add(new ValidationSchema
{
Type = "X", Enviroment = "Y", Id = 1,
Files = new List<FilesType>
{ new() { Columns = new List<Column>(), HeadersColumns = new List<Column>(), Id = 2 } }
});
await context.SaveChangesAsync();
}
using (var context = new SomeDbContext())
{
var pool = context.Set<ValidationSchema>().ToList();
}
public class SomeDbContext : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder
.UseCosmos(
"https://localhost:8081",
"C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==",
"PointReads")
.LogTo(Console.WriteLine, LogLevel.Information)
.EnableSensitiveDataLogging();
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<ValidationSchema>(builder =>
{
builder.HasPartitionKey(f => f.Type);
builder.HasKey(f => new { f.Id, f.Enviroment, f.Deleted });
builder.OwnsMany(x => x.Files, files =>
{
files.OwnsMany(om => om.Columns);
files.OwnsMany(om => om.HeadersColumns);
});
});
}
}
public class ValidationSchema
{
public int Id { get; set; }
public string Type { get; set; }
public ICollection<FilesType>? Files { get; set; }
public string Enviroment { get; set; }
public bool Deleted { get; set; }
}
public class FilesType
{
public int Id { get; set; }
public bool IsMain { get; set; }
public string? Name { get; set; }
public ICollection<Column>? Columns { get; set; }
public ICollection<Column>? HeadersColumns { get; set; }
}
public class Column
{
public int Id { get; set; }
public string? ColumnName { get; set; }
public bool IsMain { get; set; }
public int ColumnIndex { get; set; }
public int CheckIndex { get; set; }
public string? DateTimeFormat { get; set; }
public string? Description { get; set; }
} |
https://github.com/PiotrKadziewicz/testefcore This is the code pulled from the app. If you use EF Cosmos 8.0.0 for writing and reading it's not a problem. But when I write with 7.0.13 and read with 8.0.0, I get this error |
Write difference between EF 7.0.13 and 8.0.0
|
removing "int Id" from models helped |
Note for triage: this is an intentional change (#31664), but we should discuss how to deal with the breaking change where old documents will not load. @PiotrKadziewicz For 7.0.14, you can set the following AppContext switch to the old behavior: AppContext.SetSwitch("Microsoft.EntityFrameworkCore.Issue31664", true); This switch will not work on 8.0. |
I removed the Id properties from the entity. From what I remember, it also had to be added because after an update ef core did not load them without ID. They are no longer needed. Message: no unique key. It's ok now, thanks |
Include your code
Error occurs on
public ICollection properties? Columns { get; set; }
public ICollection? HeadersColumns { get; set; }
If they are commented out or ef core is 7.013 or lower, the error does not occur
EF Core version: 7.0.14
Database provider: Microsoft.EntityFrameworkCore.Cosmos
Target framework: .net 7
Operating system: Windows 11
IDE: (e.g. Visual Studio 2022 17.8)
The text was updated successfully, but these errors were encountered: