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

Include with Join stopped working on preview9 #17664

Closed
solvingproblemswithtechnology opened this issue Sep 6, 2019 · 5 comments
Closed

Include with Join stopped working on preview9 #17664

solvingproblemswithtechnology opened this issue Sep 6, 2019 · 5 comments

Comments

@solvingproblemswithtechnology

Having a query like this:

dbset
    .Include(a => a.NavigationProperty)
    .Join(dbset1, left => left.Id, right => right.Id,
        (left, right) => new { Left = left, Right = right })
    .ToList();

The Property "NavigationProperty" is null. This is working on preview8.

Steps to reproduce

Having three entities with a NavigationProperty. Join a query with Includes.

Further technical details

EF Core version: 3.0.0-preview9.19423.6
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows 10
IDE: Visual Studio 2019 16.3.0 preview 3.0

@smitpatel
Copy link
Contributor

I am not able to reproduce this.
Here is the repro code

using System;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

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

                // Seed database
                db.Add(new Blog
                {
                    BlogDetails = new BlogDetails { Value = "BlogDetails" },
                    Title = "FirstBlog"
                });

                db.Add(new Author { Name = "First" });

                db.SaveChanges();
            }

            using (var db = new MyContext())
            {
                // Run queries
                var query = db.Blogs.Include(b => b.BlogDetails)
                    .Join(db.Authors, l => l.Id, r => r.Id, (l, r) => new { l, r })
                    .ToList();

                Console.WriteLine(query[0].l.Title);
                Console.WriteLine(query[0].l.BlogDetails.Value);
                Console.WriteLine(query[0].r.Name);
            }

            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; }
        public DbSet<Author> Authors { 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
        }
    }

    public class Blog
    {
        public int Id { get; set; }
        public string Title { get; set; }
        public BlogDetails BlogDetails { get; set; }
    }

    public class BlogDetails
    {
        public int Id { get; set; }
        public string Value { get; set; }
    }

    public class Author
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }
}

Output

FirstBlog
BlogDetails
First
Program finished.

Please post a runnable project (or modify above repro code) to demonstrate the issue you are seeing.

@DanoThom
Copy link

DanoThom commented Sep 9, 2019

NOTE: I'm using the cosmosDb provider.

I can confirm this too in both dotnet and aspnetcore using the above code using the latest version 3.0.0-preview9.19423.6.

Additionally, Preview9 seems to now require explicit values or a model value generator for the int Id's in each model object or it fails.

image

@smitpatel
Copy link
Contributor

CosmosDb does not support join on server side. Hence EF Core cannot translate it to server.

@divega
Copy link
Contributor

divega commented Sep 9, 2019

@AndriySvyryd to find the duplicate.

@smitpatel
Copy link
Contributor

Duplicate of #16920

@smitpatel smitpatel marked this as a duplicate of #16920 Sep 9, 2019
@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

5 participants