Support structs in DbContext.Database.SqlQuery<T>()
- Dominant language
- C#
- Stars
- 14.8k
- Forks
- 3.4k
- PR merge metrics
- PR metrics pending
Description
### What problem are you trying to solve?
I would like to have value type support. Try this code sample below.
Currently you get this Unhandled exception. `System.ArgumentException: The specified type 'NameAndPrice' must be a non-interface reference type to be used as an entity type`.
```cs
using var ctx = new NorthwindContext();
var price = 40M;
var result = ctx.Database.SqlQuery(
$"select ProductName, UnitPrice from dbo.Products where UnitPrice > {price}");
foreach (var item in result) {
Console.WriteLine($"{item.ProductName} {item.UnitPrice:C2} ");
}
internal record struct NameAndPrice(string ProductName, decimal UnitPrice) {
public static implicit operator (string ProductName, decimal UnitPrice)(NameAndPrice value) {
return (value.ProductName, value.UnitPrice);
}
public static implicit operator NameAndPrice((string ProductName, decimal UnitPrice) value) {
return new NameAndPrice(value.ProductName, value.UnitPrice);
}
}
```
Please remove the non-interface reference type limitation. Dapper supports this, EF Core should do this too.
### Describe the solution you'd like
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.