How to use EF Include method(to load related data) in F#?

Viewed 194

How to eager load related data in F# using Include method I tried this one: _ctx.Reports.Include(x => x.Category) and getting the following error:

Severity Code Description Project File Line Suppression State Error FS0041 A unique overload for method 'Include' could not be determined based on type information prior to this program point. A type annotation may be needed.

Known type of argument: ^_arg3

Candidates: - (extension) Linq.IQueryable.Include<'TEntity when 'TEntity : not struct>(navigationPropertyPath: string) : Linq.IQueryable<'TEntity> - (extension) Linq.IQueryable.Include<'TEntity,'TProperty when 'TEntity : not struct>(navigationPropertyPath: Linq.Expressions.Expression>) : Query.IIncludableQueryable<'TEntity,'TProperty> SharpNews.Application E:\0DevelopingLearn\BackEnd\ASP.NET Core\SharpNews\SharpNews.Application\Admin\Report\GetReports.fs 44 Active

and also two errors are saying x is undefined

Am I using an incorrect syntax?

1 Answers

Casting to seq or IEnumerable<_> will do the trick

context.Users
    .Include(fun u -> u.Roles :> seq<Role>)
open System.Collections.Generic

context.Users
    .Include(fun u -> u.Roles :> IEnumerable<Role>)
        .ThenInclude(fun r -> r.Permissions)
Related