dotnet / dotnet/efcore

Feature Request: Adding Support for Tuples in DbContext.Database.SqlQuery<T>()

Open
#35,163 27 comments 12 reactions 0 assignees View on GitHub
area-query consider-for-next-release customer-reported
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

Currently, Entity Framework does not support using tuples as the generic type in the `DbContext.Database.SqlQuery()` method. This limitation makes it challenging to execute SQL queries that return columns that do not directly map to entities or predefined models in the code.

I would like Entity Framework to support tuples as the generic type in DbContext.Database.SqlQuery(). For example:

```csharp
var results = context.Database.SqlQuery<(int Id, string Name)>("SELECT Id, Name FROM TableName");
```
This would allow developers to work directly with strongly-typed tuple results, simplifying development and eliminating the need for additional classes to handle temporary or specific query results.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.