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

Incorrect result when doing owner + include collection + split query + owned type mapped to different table + single #23276

Closed
smitpatel opened this issue Nov 11, 2020 · 2 comments
Assignees
Labels
area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported Servicing-approved type-bug
Milestone

Comments

@smitpatel
Copy link
Contributor

public class Program
    {
        public static async Task Main(string[] args)
        {
            using (var db = new MyContext())
            {
                // Recreate database
                db.Database.EnsureDeleted();
                db.Database.EnsureCreated();

                // Seed database
                db.Add(new Blog
                {
                    Owned = new OwnedType { Value = "A" },
                    Posts = new List<Post>
                    {
                        new Post{Title = "ABC"},
                        new Post{Title = "DEF"},
                    }
                });

                db.SaveChanges();
            }

            using (var db = new MyContext())
            {
                // Run queries
                var query = db.Blogs.Include(e => e.Posts).AsSplitQuery().OrderBy(e => e.Id).Single();

                Console.WriteLine(query.Posts.Count);
            }
            Console.WriteLine("Program finished.");
        }
    }


    public class MyContext : DbContext
    {
        private static ILoggerFactory ContextLoggerFactory
            => LoggerFactory.Create(b =>
            {
                b
                .AddConsole()
                .AddFilter("", LogLevel.Debug);
            });

        // Declare DBSets
        public DbSet<Blog> Blogs { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            // Select 1 provider
            optionsBuilder
                .UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=_ModelApp;Trusted_Connection=True;Connect Timeout=5;ConnectRetryCount=0")
                //.UseSqlite("filename=_modelApp.db")
                //.UseInMemoryDatabase(databaseName: "_modelApp")
                //.UseCosmos("https://localhost:8081", @"C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==", "_ModelApp")
                .EnableSensitiveDataLogging()
                .UseLoggerFactory(ContextLoggerFactory);
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            // Configure model
            modelBuilder.Entity<Blog>().OwnsOne(e => e.Owned, b => b.ToTable("Owned"));
        }
    }

    public class Blog
    {
        public int Id { get; set; }
        public OwnedType Owned { get; set; }
        public List<Post> Posts { get; set; }
    }

    [Owned]
    public class OwnedType
    {
        public string Value { get; set; }
    }

    public class Post
    {
        public int Id { get; set; }
        public string Title { get; set; }
    }

Version 5.0

@smitpatel
Copy link
Contributor Author

@ajcvickers - Same root cause as #23211 also causes this issue. The PR #23273 fixes both.

@smitpatel
Copy link
Contributor Author

While this is already being fixed as the other issue, this error makes it higher priority to patch this as it is data corruption.

@smitpatel smitpatel added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Nov 11, 2020
@ajcvickers ajcvickers added this to the 5.0.1 milestone Nov 12, 2020
smitpatel added a commit that referenced this issue Nov 17, 2020
smitpatel added a commit that referenced this issue Nov 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported Servicing-approved type-bug
Projects
None yet
Development

No branches or pull requests

2 participants