question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Projections With Full Types Not Fixing Up Navigations on Sqlite and SQL Server

See original GitHub issue

I’ve searched for a related issue as well as blog posts/docs and am not finding anything. I know it’s out there somewhere but have to stop looking!

Also related to https://github.com/aspnet/EntityFramework/issues/4007

Steps to reproduce

using System.Collections.Generic;
using System.Linq;
using Microsoft.EntityFrameworkCore;

namespace ProjectionProblem
{
  public class Parent
  {
    public Parent()
    {
      Children = new List<Child>();
    }

    public int Id { get; set; }
    public string Description { get; set; }
    public List<Child> Children { get; set; }
  }

  public class Child
  {
    public int Id { get; set; }
    public string Description { get; set; }
  }

  public class MyContext : DbContext
  {
    public DbSet<Parent> Parents { get; set; }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
      optionsBuilder.UseSqlite("Data source=ProjectionProblem.db");
    }
  }

  public class Program
  {
    private static void Main(string[] args)
    {
      using (var context = new MyContext())
      {
        context.Database.EnsureDeleted();
        context.Database.EnsureCreated();
        var parent = new Parent {Description = "Parent1"};
        parent.Children.Add(new Child {Description = "Child1"});
        parent.Children.Add(new Child {Description = "Child2"});
        context.Parents.Add(parent);
        context.SaveChanges();
      }
      using (var context2 = new MyContext())
      {
        var newtype = context2.Parents.Select(p => new {Parent = p, p.Children}).ToList();
      }
    }
  }
}

The issue

Navigations not being fixed up in results. newtype.Children has the child objects, but newtype.Parent.Children is empty.

Further technical details

EF Core version: 1.1 Operating system: Visual Studio version: vs2015 but really not applicable

Other details about my project setup:

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:31 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
anpetecommented, Jun 28, 2017

Closing as fixed in 2.0

1reaction
anpetecommented, Jun 28, 2017

Thanks for taking the time to try this out!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Exception when using EF Core InMemory and a projection ...
In our real code, using the SQL Server provider (at runtime) works and does not error, as with SQLite. Using the InMemory provider...
Read more >
Efficient Querying - EF Core
Performance guide for efficient querying using Entity Framework Core.
Read more >
Complex Query Operators - EF Core
Language Integrated Query (LINQ) contains many complex operators, which combine multiple data sources or does complex processing. Not all LINQ ...
Read more >
Entity Framework Core 5 - Pitfalls To Avoid and Ideas to Try
In this post, we'll look at some pitfalls and ideas EF Core users like yourself may want to consider when developing an application....
Read more >
Save data using SQLite
Saving data to a database is ideal for repeating or structured data, such as contact information. This page assumes that you are familiar...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found