Skip to content

Intercept resolution of entity type #34765

Open

Description

@kjkrum

IMaterializationInterceptor allows the interception of individual entity materialization. Conceptually there must be a preceding step where EF resolves the entity type that a database row will be materialized into. It may be useful to intercept that type resolution.

My use case for this feature would be to examine authorization attributes on the entity type and throw an exception if the current user is not authorized to access that entity type. I'm currently doing this experimentally with an IMaterializationInterceptor. This feature request is based on the possibly incorrect assumption that type resolution only occurs once for a result set, as opposed to materialization which occurs once for every row. My entire use case may prove to be a stupid idea, but there may be more legitimate use cases for a type resolution interceptor.

Activity

  1. AndriySvyryd commented on Oct 4, 2024

    @AndriySvyryd
    Member

    Type resolution does occur once for every row (roughly). Currently this logic is hardcoded but might be possible to do something like this after #32923 is implemented.

  2. added this to the Backlog milestone on Oct 4, 2024
  3. roji commented on Oct 4, 2024

    @roji
    Member

    @kjkrum I'd be interested in more context on exactly what you're trying to achieve, i.e. how exactly you would vary the entity type being materialized, and why - there may be simpler ways to achieve the same overall goal.

  4. kjkrum commented on Oct 4, 2024

    @kjkrum
    Author

    @roji I'm not interested in changing the entity type, only examining its attributes to see if the current user is authorized to load entities of that type. In other words, roughly speaking, table-level permissions. A materialization interceptor works for this, and performance isn't an issue yet, but maybe it could be more efficient.

  5. added theissue type on Jun 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions