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

Interception point that gets the returned data after serialization #32418

Closed
gdoron opened this issue Nov 27, 2023 · 5 comments
Closed

Interception point that gets the returned data after serialization #32418

gdoron opened this issue Nov 27, 2023 · 5 comments
Labels
closed-no-further-action The issue is closed and no further action is planned. customer-reported

Comments

@gdoron
Copy link

gdoron commented Nov 27, 2023

Hi,

(With some obfuscation because of IP)
All our mapped to EF database entities are deriving from BaseClass:

public class BaseEntity {
  public string RequiredPermission { get; set; }
}

We are trying to validate that no matter what, the data returned from the database does not include rows the current user doesn't have permission to, (even if the developer used set.IgnoreQueryFilter()

We would like having another interception point, with the reference to the data returned from the database after serialization, instead of having to materialize the DbDataReader twice.

@ajcvickers
Copy link
Member

with the reference to the data returned from the database after serialization

Can you be more specific about what you mean by this?

@gdoron
Copy link
Author

gdoron commented Nov 30, 2023

@ajcvickers Consider this code:

await dbContext.Set<Person>().Where(x=> x.Name.Contains("foo").ToListAsync()

We would want to have an interceptor that gets the List<Person>? as the object? Results property of a new interception point of DbCommandInterceptor.

Does it make sense?

@ajcvickers
Copy link
Member

@gdoron Yes, but this isn't something that EF can do directly, since enumeration of the query results and the completion of this isn't triggered by EF Core, and EF Core doesn't know what has been done with the results. There is quite a long discussion about this on #23535, and in EF7 we introduced DataReaderClosing that is triggered used when the result set has been consumed. See: https://learn.microsoft.com/en-us/ef/core/what-is-new/ef-core-7.0/whatsnew#new-and-improved-interceptors-and-events

@ajcvickers ajcvickers added the closed-no-further-action The issue is closed and no further action is planned. label Dec 5, 2023
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Dec 5, 2023
@gdoron
Copy link
Author

gdoron commented Dec 11, 2023

@ajcvickers I'm afraid I did not understand how to use the DataReaderClosing method for our use case.
How can we get the List<T> that was read from that DataReader?

@ajcvickers
Copy link
Member

ajcvickers commented Dec 11, 2023

@gdoron EF doesn't ever create a List<T>. EF reads values from the DbDataReader and inserts them directly into your entity instances without going through any intermediary data structure. The application then determines what to do with each instance streamed back. At that point the application may create a List<T> if it chooses. If you're looking for some kind of data structure that goes between the DbDataReader and the materialized entities, then that doesn't exist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-no-further-action The issue is closed and no further action is planned. customer-reported
Projects
None yet
Development

No branches or pull requests

2 participants