You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support for mapping entity types to defining queries #13358
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.
Reacted by Vasim Hanna-Salem, Dean M Zamzow, Brice Lambson and Lajith
Note to implementor: use IRawSqlResult to store the mapping in the relational model. Also add overload for it and IStoreFunction to IRelationalAnnotationProvider
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.
Activity
ajcvickers commentedon Apr 8, 2019
See also the discussion in #15239
divega commentedon Aug 19, 2019
Reactivating and marking as punted for 3.0 since we are disabling this again as per #17157.
7 remaining items
AndriySvyryd commentedon Jul 6, 2020
Note to implementor: use
IRawSqlResultto store the mapping in the relational model. Also add overload for it andIStoreFunctiontoIRelationalAnnotationProvidersmitpatel commentedon Jul 6, 2020
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.
AndriySvyryd commentedon Jul 6, 2020
IRawSqlResultwould also have parameter mapping and have a unique name to allow multipleFromSqlshapes for the same entity type.Allow mapping entity types to SQL queries
Allow mapping entity types to SQL queries
Allow mapping entity types to SQL queries