Skip to content

VisualBasic semantic model does not recognize overloads at chained queries #35096

@ivanbasov

Description

@ivanbasov
Imports System.Linq.Expressions

Namespace ThenIncludeIntellisenseBug

    Class Program
        Shared Sub Main(args As String())
            Dim registrations = New List(Of Registration)().AsQueryable()
            Dim reg = registrations.Include(Function(r) r.Activities).ThenInclude(Function(a, b, c) c.F)
        End Sub
    End Class

    Friend Class Registration
        Public Property Activities As ICollection(Of Activity)
    End Class

    Public Class Activity
        Public Property Task As Task
    End Class

    Public Class Task
        Public Property Name As String
    End Class

    Public Interface IIncludableQueryable(Of Out TEntity, Out TProperty)
        Inherits IQueryable(Of TEntity)
    End Interface

    Public Module EntityFrameworkQuerybleExtensions
        <System.Runtime.CompilerServices.Extension>
        Public Function Include(Of TEntity, TProperty)(
                                                      source As IQueryable(Of TEntity),
                                                      navigationPropertyPath As Expression(Of Func(Of TEntity, TProperty))) As IIncludableQueryable(Of TEntity, TProperty)
            Return Nothing
        End Function

        <System.Runtime.CompilerServices.Extension>
        Public Function ThenInclude(Of TEntity, TPreviousProperty, TProperty)(
                                                                             source As IIncludableQueryable(Of TEntity, ICollection(Of TPreviousProperty)),
                                                                             navigationPropertyPath As Expression(Of Func(Of String, TPreviousProperty, TProperty))) As IIncludableQueryable(Of TEntity, TProperty)
            Return Nothing
        End Function

        <System.Runtime.CompilerServices.Extension>
        Public Function ThenInclude(Of TEntity, TPreviousProperty, TProperty)(
                                                                             source As IIncludableQueryable(Of TEntity, TPreviousProperty),
                                                                             navigationPropertyPath As Expression(Of Func(Of String, String, TPreviousProperty, TProperty))) As IIncludableQueryable(Of TEntity, TProperty)
            Return Nothing
        End Function

    End Module
End Namespace

VB displays the following diagnostic
BC36532 Nested function does not have the same signature as delegate 'Func(Of String, Activity, Object)'.

Then, if place caret after F and you type CTRL+J, it would provide completion for object not for ICollection<>.

Compare with C#

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, b, c) => c.F);
        }
    }

    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<string, 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<string, string, TPreviousProperty, TProperty>> navigationPropertyPath) where TEntity : class
        {
            return default(IIncludableQueryable<TEntity, TProperty>);
        }
    }
}

C# provides
CS1061 'ICollection<Activity>' does not contain a definition for 'F' and no accessible extension method 'F' accepting a first argument of type 'ICollection<Activity>' could be found (are you missing a using directive or an assembly reference?)
and it works properly with CTRL + J.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions