VS fails to show proper intellisense when using multiple ThenIncludes
See this SO post.
I was trying another .Include(blah).ThenInclude(blah), and while intellisense worked for the first, the second only showed IEnumberable functions/methods which lead me to believe I had mistyped something or it wasn't supported somehow.
For example...
var reg = _context.Registrations
.Where(r => r.User.UserName == userName)
.Include(r => r.Activities).ThenInclude(a => a.Task)
.Include(r => r.Activities).ThenInclude(a => a.Responses)
.FirstOrDefault();
The second a in the second ThenInclude did not show this as being a valid property. Thanks to the contributor to my SO post I tried building and running it anyways and it worked fine. VS lead me astray! ;) Is this the proper place to report this?
VS Info...
Microsoft Visual Studio Professional 2015 Version 14.0.24720.00 Update 1 Microsoft .NET Framework Version 4.6.01055 Installed Version: Professional
EF info (as per project.json & "References" tree control in VS)...
EntityFramework.Core (7.0.0-rc1-final)
Some more details...
Here are the two definitions of ThenInclude. The issue is that after calling .Include on a collection, IntelliSense uses the second overload.
public static IIncludableQueryable<TEntity, TProperty> ThenInclude<TEntity, TPreviousProperty, TProperty>(this IIncludableQueryable<TEntity, ICollection<TPreviousProperty>> source, Expression<Func<TPreviousProperty, TProperty>> navigationPropertyPath) where TEntity : class;
public static IIncludableQueryable<TEntity, TProperty> ThenInclude<TEntity, TPreviousProperty, TProperty>(this IIncludableQueryable<TEntity, TPreviousProperty> source, Expression<Func<TPreviousProperty, TProperty>> navigationPropertyPath) where TEntity : class;
This is unfortunate because chaining after calling Include on a collection is the primary use case for ThenInclude. After a reference, you have the option of just dotting thru within the Include call.
@divega to file an issue with VS
Here is a self-contained repro (i.e. no EF in the picture but just API mockups):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
namespace ThenIncludeIntellisenseBug
{
class Program
{
static void Main(string[] args)
{
var registrations = new List<Registration>().AsQueryable();
var reg = registrations
.Include(r => r.Activities).ThenInclude(a => a.Task);
// type "a => a." and only ICollection<T> and Enumerable members appear
}
}
internal class Registration
{
public ICollection<Activity> Activities { get; set; }
}
public class Activity
{
public Task Task { get; set; }
}
public class Task
{
public string Name { get; set; }
}
public interface IIncludableQueryable<out TEntity, out TProperty> : IQueryable<TEntity>
{
}
public static class EntityFrameworkQuerybleExtensions
{
public static IIncludableQueryable<TEntity, TProperty> Include<TEntity, TProperty>(
this IQueryable<TEntity> source,
Expression<Func<TEntity, TProperty>> navigationPropertyPath)
where TEntity : class
{
return default(IIncludableQueryable<TEntity, TProperty>);
}
public static IIncludableQueryable<TEntity, TProperty> ThenInclude<TEntity, TPreviousProperty, TProperty>(
this IIncludableQueryable<TEntity, ICollection<TPreviousProperty>> source,
Expression<Func<TPreviousProperty, TProperty>> navigationPropertyPath) where TEntity : class
{
return default(IIncludableQueryable<TEntity, TProperty>);
}
public static IIncludableQueryable<TEntity, TProperty> ThenInclude<TEntity, TPreviousProperty, TProperty>(
this IIncludableQueryable<TEntity, TPreviousProperty> source,
Expression<Func<TPreviousProperty, TProperty>> navigationPropertyPath) where TEntity : class
{
return default(IIncludableQueryable<TEntity, TProperty>);
}
}
}
This is now tracked as an Intellisense issue: https://github.com/dotnet/roslyn/issues/8237.
Btw the I am facing the same issue on mono (omnisharp) on mac
@ahmad-moussawi feel free to post this information to the Roslyn bug. It can help prioritizing the issue.
Closing as this is an external issue in Roslyn
@divega: @smitpatel is seeing this work correctly now. Can you confirm on your machine?
@smitpatel I can still repro this on my machine, both with EF Core and with the fake code from https://github.com/dotnet/roslyn/issues/8237. I have Visual Studio 15.3.5, no R#. Any differences you can think of?
@divega I can confirm that the issue is still active once again at Visual Studio 15.4.0

Would it be an option to have two differently named methods instead of two overloads?
This issue has been resolved in upcoming release of VS 16.1
This issue has been resolved in upcoming release of VS 16.1
I'm with VS 16.3.9 and still see it.
The difference with the example from Roslyn issue is that there the collection overload is defined as
this IIncludableQueryable<TEntity, ICollection<TPreviousProperty>> source
while in EF Core it is
this IIncludableQueryable<TEntity, IEnumerable<TPreviousProperty>> source
So when the navigation property type is ICollection<T> (or some other enumerable derived interface), the Intellisense does not offer T members initially. If the navigation property type is IEnumerable<T>, it works.
@powermetal63 - Please file an issue on roslyn repo.