-
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
Owned types in table per hierarchy cause duplicate rowversion column in query that then throws system exception #27888
Labels
area-model-building
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
customer-reported
type-bug
Milestone
Comments
KillerBoogie
changed the title
Owned types in table per hierarchy duplicate rowversion column in query which then causes a crash
Owned types in table per hierarchy cause duplicate rowversion column in query that then leads to system exception
Apr 26, 2022
KillerBoogie
changed the title
Owned types in table per hierarchy cause duplicate rowversion column in query that then leads to system exception
Owned types in table per hierarchy cause duplicate rowversion column in query that then throws system exception
Apr 26, 2022
Notes for triage: Query expression:
Model:
Code: #nullable enable
public static class Your
{
public static string ConnectionString = @"Data Source=(LocalDb)\MSSQLLocalDB;Database=SixOh";
}
public abstract class Account
{
public Guid Id { get; set; }
public ulong _etag { get; set; }
public Account(Guid id, ulong etag)
{
Id = id;
_etag = etag;
}
protected Account() { }
}
public class Person : Account
{
public FullName FullName { get; set; }
public Person(Guid id, FullName fullName, ulong etag) : base(id, etag)
{
FullName = fullName;
}
protected Person() { }
}
public class FullName
{
public string FirstName { get; set; }
public string LastName { get; set; }
public FullName(string firstName, string lastName)
{
FirstName = firstName;
LastName = lastName;
}
}
public class AccountConfiguration : IEntityTypeConfiguration<Account>
{
public void Configure(EntityTypeBuilder<Account> entity)
{
entity.ToTable("Account", "AC");
entity.HasDiscriminator<string>("Type");
entity.Property(e => e._etag).IsRowVersion().HasConversion<byte[]>();
}
}
public class PersonConfiguration : IEntityTypeConfiguration<Person>
{
public void Configure(EntityTypeBuilder<Person> entity)
{
entity.ToTable("Account", "AC");
entity.OwnsOne(e => e.FullName, e =>
{
e.Property(e => e.FirstName).HasColumnName("FirstName");
e.Property(e => e.LastName).HasColumnName("LastName");
});
}
}
public class SomeDbContext : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder
.UseSqlServer(Your.ConnectionString)
.LogTo(Console.WriteLine, LogLevel.Debug)
.EnableSensitiveDataLogging();
public DbSet<Account> Accounts { get; set; }
public DbSet<Person> People { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
new PersonConfiguration().Configure(modelBuilder.Entity<Person>());
new AccountConfiguration().Configure(modelBuilder.Entity<Account>());
}
}
public class Program
{
public static void Main()
{
Guid accountId = new Guid("da19e7f2-2520-48fd-9a52-d90c5e2d1e6b");
using (var context = new SomeDbContext())
{
context.Database.EnsureDeleted();
context.Database.EnsureCreated();
context.Add(new Person(accountId, new FullName("A", "V"), 0l));
context.SaveChanges();
}
using (var context = new SomeDbContext())
{
var account = context.Accounts.SingleOrDefault(e => e.Id == accountId);
}
}
} |
Could be related to #22584 |
My colleague found a workaround. You need to define the etag property in every OwnsType hat is in the entity. So it seems to be related to #22584
|
AndriySvyryd
added
the
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
label
Sep 1, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
area-model-building
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
customer-reported
type-bug
We ran into a major issue using table per hierarchy. The base class has a
RowVersion
attribute. When the table is queried the created query includes theRowVersion
column twice and crashes withThis only happens when a derived class has an owned type and therefore no converter!
Here is an example:
LINQ
Created Query: [a].[_etag] is doubled in select
Classes
Configuration
Include provider and version information
EF Core version: 6.04
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 6.0
Operating system: Win 10
IDE: Visual Studio 2022 17.1.2
The text was updated successfully, but these errors were encountered: