Skip to content

Add support for projectable method overloads #58

@willnationsdev

Description

@willnationsdev

If I try to define 2+ projectable methods with the same name on the same class but give them different argument lists, then the source generator triggers an error indicating that classes with the same name cannot be provided by the same source generator. It appears this is because the class name is generated via the namespace+class+method. Would it be difficult/problematic to expand this so that the generated class names also include the number and type of the arguments? For example...

namespace MyNamespace
{
    class MyClass
    {
        [Projectable] public MyImage? FindImage(DbContext db, int id) => db.Set<MyImage>().Where(m => true);
        [Projectable] public MyImage? FindImage(DbContext db, Uri uri) => db.Set<MyImage>().Where(m => true);
        [Projectable] public MyImage? FindImage(DbContext db, Uri folder, string tagName) => db.Set<MyImage>().Where(m => true);
    }
}
  • EntityFrameworkCore.Projectables.Generated.MyNamespace_MyClass_FindImage_P1_System_Int32
  • EntityFrameworkCore.Projectables.Generated.MyNamespace_MyClass_FindImage_P1_System_Uri
  • EntityFrameworkCore.Projectables.Generated.MyNamespace_MyClass_FindImage_P1_System_Uri_P2_System_String

It's important to note that this is more of a nice-to-have. I attempted to do method overloads and ran into this error, after which I had to work around it by using a naming convention like, FindImageById, FindImageByUri, FindImageByFolderAndTag, etc. It did not significantly impact my ability to use this library, but it was something I wanted to do and which I was disappointed to discover I could not do. However, I can understand if one would not wish to work on adding it as a feature.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions