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

FixUp: Collection properties incorrect #4853

Closed
bricelam opened this issue Mar 18, 2016 · 0 comments
Closed

FixUp: Collection properties incorrect #4853

bricelam opened this issue Mar 18, 2016 · 0 comments
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Milestone

Comments

@bricelam
Copy link
Contributor

class TestAssembly
{
    [Key]
    public string Name { get; set; }
    public ICollection<TestClass> Classes { get; } = new List<TestClass>();
}

class TestClass
{
    public TestAssembly Assembly { get; set; }
    public string Name { get; set; }
}

class Context : DbContext
{
    public DbSet<TestAssembly> Assemblies { get; set; }
    public DbSet<TestClass> Classes { get; set; }

    protected override void OnConfiguring(DbContextOptionsBuilder options)
        => options.UseSqlite("Data Source=ConsoleApplication1.db");

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<TestClass>(
            x =>
            {
                x.Property<string>("AssemblyName");
                x.HasKey("AssemblyName", nameof(TestClass.Name));
                x.HasOne(c => c.Assembly).WithMany(a => a.Classes)
                    .HasForeignKey("AssemblyName");
            });
    }
}

class Program
{
    static void Main()
    {
        using (var db = new Context())
        {
            db.Database.EnsureDeleted();
            db.Database.EnsureCreated();

            // Seed the database
            var assembly = new TestAssembly { Name = "Assembly1" };
            db.Classes.Add(new TestClass { Assembly = assembly, Name = "Class1" });
            db.Classes.Add(new TestClass { Assembly = assembly, Name = "Class2" });
            db.SaveChanges();
        }

        using (var db = new Context())
        {
            db.Classes.Include(c => c.Assembly).Load();
            var assembly = db.ChangeTracker.Entries<TestAssembly>().Select(e => e.Entity)
                .Single();

            // Fails with "count was 1"
            var count = assembly.Classes.Count;
            Debug.Assert(count == 2, "count was " + count);
        }
    }
}
@rowanmiller rowanmiller added this to the 1.0.0 milestone Mar 25, 2016
ajcvickers added a commit that referenced this issue Apr 7, 2016
…gations

Issue #4853

The issue here is when the second TestClass was loaded the relationship snapshot on the inverse was not updated, which in turn caused DetectChanges to misbehave. Rather than attempt to do any kind of diff at the end of query the fix is to update the relationship snapshot at the same time that query is setting or populating the actual navigation property.
ajcvickers added a commit that referenced this issue Apr 8, 2016
…gations

Issue #4853

The issue here is when the second TestClass was loaded the relationship snapshot on the inverse was not updated, which in turn caused DetectChanges to misbehave. Rather than attempt to do any kind of diff at the end of query the fix is to update the relationship snapshot at the same time that query is setting or populating the actual navigation property.
@ajcvickers ajcvickers added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Oct 15, 2022
@ajcvickers ajcvickers removed their assignment Sep 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Projects
None yet
Development

No branches or pull requests

3 participants