Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for projectable method overloads #58

Open
willnationsdev opened this issue Jan 21, 2023 · 2 comments
Open

Add support for projectable method overloads #58

willnationsdev opened this issue Jan 21, 2023 · 2 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@willnationsdev
Copy link

willnationsdev commented Jan 21, 2023

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.

@koenbeuk
Copy link
Owner

Thanks for suggesting this, I agree that this should be supported and the suggested approach sounds fair.

@douglasg14b
Copy link

For now a helpful error would probably be a good patch. I didn't realize this limitation and was hitting my head against a wall on this for ages. When I added overloaded methods every query would start failing as their projectables couldn't be resolved.

Turns out it was because of a newly added overload!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants