Entityframework.docs: How do you do .ThenInclude from F#?

Created on 8 Aug 2018  Â·  3Comments  Â·  Source: dotnet/EntityFramework.Docs

After figuring out how to get the proxies to work in F# https://github.com/aspnet/EntityFrameworkCore/issues/12923, I tried to create queries using something like .Include(fun blog -> blog.Posts).ThenInclude(fun post -> post.Author), but post ends up being a collection. It fails in IntelliSense and during compilation. How do I make it work? Is there a workaround?


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

closed-question help wanted

Most helpful comment

@ctaggart We can look into this, but two things I can mention off the top of my head:

  • Visual Studio IntelliSense doesn't work for this in C#--see https://github.com/dotnet/roslyn/issues/8237 (ReSharper/Ryder IntelliSense works fine for me.)
  • You could try using string-based Include. That is, dot-separated navigation properties: .Include("Posts.Author")

All 3 comments

@ctaggart We can look into this, but two things I can mention off the top of my head:

  • Visual Studio IntelliSense doesn't work for this in C#--see https://github.com/dotnet/roslyn/issues/8237 (ReSharper/Ryder IntelliSense works fine for me.)
  • You could try using string-based Include. That is, dot-separated navigation properties: .Include("Posts.Author")

I can confirm that the string version of Include is working in F#.

@manchoz's comment shows how to do it without hardcoding strings:

F# won't automatically upcast List<T> to IEnumerable<T>. Explicitly upcasting the .Include() lambda to IEnumberable<T> seems to resolve the issue:

let q =
    db.Schemas
       .Include(fun sch -> sch.Entities :> IEnumerable<_>)
           .ThenInclude(fun (ents : Entity) -> ents.Fields)
       .ToList()
Was this page helpful?
0 / 5 - 0 ratings

Related issues

norvegec picture norvegec  Â·  3Comments

jpeckham picture jpeckham  Â·  3Comments

davidliang2008 picture davidliang2008  Â·  4Comments

joakimriedel picture joakimriedel  Â·  3Comments

mjehle82 picture mjehle82  Â·  3Comments