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

Ef Core 5 Owned on Entity with HiLo Error #24679

Closed
borisgr04 opened this issue Apr 17, 2021 · 1 comment
Closed

Ef Core 5 Owned on Entity with HiLo Error #24679

borisgr04 opened this issue Apr 17, 2021 · 1 comment

Comments

@borisgr04
Copy link

borisgr04 commented Apr 17, 2021

Ef Core 5 Owned en Entity with HiLo it

Build started...
Build succeeded.
System.InvalidOperationException: 'Contacto.Id' and 'Direccion.ContactoId' are both mapped to column 'Id' in 'Contacto' but are configured with different value generation strategies.

In Ef Core 3 It works correctly.

Code

public class Context : DbContext 
    {
        public DbSet<Contacto> Contacto { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
            => optionsBuilder.UseSqlServer("Data Source=.\\;Database=OwnedDataBaseTest;Trusted_Connection=True;MultipleActiveResultSets=true");

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
            modelBuilder.Entity<Contacto>().HasKey(t => t.Id);
            modelBuilder.Entity<Contacto>().Property(p=>p.Id).UseHiLo("Contacto_hilo");
            modelBuilder.Entity<Contacto>().OwnsOne(p => p.Direccion);
            
        }
    }

    //[Owned]
    public class Direccion 
    {
        public string Calle { get; set; }
        public string Numero { get; set; }
    }
    public class Contacto
    {
        public int Id { get; set; }
        public string Telefono { get; set; }
        public string Nombre { get; set; }
        public Direccion Direccion { get; set; }
    }

EF Core version: 5
Database provider: (e.g. Microsoft.EntityFrameworkCore.SqlServer)
Target framework: (e.g. .NET 5.0)
Operating system: Windows
IDE: (e.g. Visual Studio 2019 16.3)

@borisgr04 borisgr04 changed the title Migrate Ef Core 3.1 to Ef Core 5.0 - but are configured with different value generation strategies Ef Core 5 Owned en Entity with HiLo Error Apr 17, 2021
@borisgr04 borisgr04 changed the title Ef Core 5 Owned en Entity with HiLo Error Ef Core 5 Owned on Entity with HiLo Error Apr 17, 2021
@ajcvickers
Copy link
Member

Looks like a duplicate of #20740. /cc @AndriySvyryd

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
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

2 participants