-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Filtered Foreign Key Attribute #21991
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
@tanekim77 Leaving syntax aside for the moment, it's not clear exactly what you expect to happen when |
@ajcvickers |
@tanekim77 - If it is for include and specified via ForeignKeyAttribute then would you expect it to be applied as filter on navigation
Would it make more sense for the configuration of filter to be tied with navigation in a different way rather than ForeignKeyAttribute? |
@smitpatel
In this case, if a student who has age < 31 is trying to include OldStudentDifficultCourses navigation property, then it would return null. |
Given we have NavigationBuilder, it would be better to put them on NavigationBuilder. modelBuilder.Entity<Student>().Navigation(e => e.Courses).HasIncludeFilter(e => e.Where(course => course.Difficulty >10)); @AndriySvyryd - Do we need a generic Navigation Builder now? |
@smitpatel Sure - #22012 |
As for the attribute notations, for either many-to-many or one-to-many, what do you think about the following notation? For one-to-many:
For many-to-many:
followed by the standard many-to-many Fluent api configuration. Or alternatively and optionally, one can choose to define both criteria on both sides just to be more clear,
|
It would be more useful to call it Regardless, before we add any attribute to configure it, we will first need to add a fluent API way for it and design whole feature. Attributes can be tricky depending on what autocompletion it provides. We are talking about writing a LINQ in an attributes ctor here. Without proper intellisense support attribute would not provide much value. |
Just a reminder that attributes are extremely limited in terms of parameter types. AFAIK C# simply does not support lambdas in attributes. However as @smitpatel suggested this could be a fluent API, which would be somewhat similar to AutoInclude API, specifying that when a navigation is included, it should be implicitly filtered. |
I am seeing the silver lining in the cloud at least in the distant future in the following link: Hopefully, if this goes through approval, then the filtered attribute feature may one day be a dream come true. |
@tanekim77 I think that issue is to allow applying attributes to lambda, rather than to allow lambdas to be passed as arguments to attributes |
Oops, facepalm. I think it's a right time to say goodbye to my pipe dream. |
Discussed in triage and decided that this is really about being able to map a navigation to some different backing query (which may do filtering.) This is tracked by #20339 |
In Entity Framework Core 5, "filtered include" feature is finally scheduled to be released.
Now, we need some love for ForeignKey attribute as well. It would be great if I can do something like the following with the ForeignKey attribute. I believe implementing this feature is easily doable using the "filtered include" feature.
This will give more flexibility in mapping relationships through ForeignKey attributes.
The text was updated successfully, but these errors were encountered: