Skip to content

Support for mapping entity types to defining queries #13358

Description

@divega

In EF Core 2.1 we added query types, which can be mapped in the model to "defining query" specified using the ToQuery API.

Such defining query is generally a LINQ query that becomes the source of data for read operations for the query type.

This issue is about adding the ToQuery API and the ability to map regular entity types to defining queries as well.

We need to consider that query types are read-only and so they don't need to be mapped to a table or underlying collection for the purpose of CUD operations.

Since entity types are not read-only, defining query mapping for entity types would work best in combination with custom CUD mapping, e.g. stored procedure mapping.

Activity

  1. added this to the Backlog milestone on Sep 19, 2018
  2. ajcvickers commented on Apr 8, 2019

    @ajcvickers
    Contributor

    See also the discussion in #15239

  3. removed this from the Backlog milestone on Aug 9, 2019
  4. added this to the 3.0.0 milestone on Aug 12, 2019
  5. removed their assignment
    on Aug 12, 2019
  6. modified the milestones: 3.0.0, Backlog on Aug 19, 2019
  7. divega commented on Aug 19, 2019

    @divega
    ContributorAuthor

    Reactivating and marking as punted for 3.0 since we are disabling this again as per #17157.

  8. reopened this on Aug 19, 2019
  9. 7 remaining items

  10. AndriySvyryd commented on Jul 6, 2020

    @AndriySvyryd
    Member

    Note to implementor: use IRawSqlResult to store the mapping in the relational model. Also add overload for it and IStoreFunction to IRelationalAnnotationProvider

  11. smitpatel commented on Jul 6, 2020

    @smitpatel
    Contributor

    We allow mapping entity type to TVF/View/Table. When generating projection in the query, we create appropriate table source and use relevant mappings.
    For non-query root translation like TVF, we are going to use function mapping (since we have mapped store function info too).

    For ad-hoc translation like FromSql, we don't have anything in model to get mappings. Additionally we are going to add ToSqlQuery which will make SQL a mix of both words (in/out of the model). Further FromSql can use any number of parameters which can change ad-hoc.
    Currently for FromSql we use the column names from view if available or from Table. We can use mapping from IRawSqlResult once implemented.

    For any other ad-hoc translation which are none of the above, we could also have default mappings.

  12. AndriySvyryd commented on Jul 6, 2020

    @AndriySvyryd
    Member

    IRawSqlResult would also have parameter mapping and have a unique name to allow multiple FromSql shapes for the same entity type.

  13. added 2 commits that reference this issue on Jul 18, 2020
    c1a10f1
    ad4ccc7
  14. removed their assignment
    on Jul 20, 2020
  15. added a commit that references this issue on Jul 20, 2020
    13e69ca
  16. modified the milestones: 5.0.0, on Aug 14, 2020
  17. modified the milestones: , 5.0.0 on Nov 7, 2020
  18. 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

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions