---
title: "Entity Framework 8: Raw SQL queries on unmapped types"
description: "The next iteration of Entity Framework, namely Entity Framework 8, will have a new and exciting feature:\n\n**Support raw SQL queries without defining an entity type for the result**\n\nThat means less boilerplate code!"
updated: 2023-01-12
tags: ["C#", "Entity Framework", ".NET 8"]
canonical: "https://steven-giesel.com/blogPost/d1f069fb-7f6d-4f80-a98f-734755474ae1/entity-framework-8-raw-sql-queries-on-unmapped-types"
---

# Entity Framework 8: Raw SQL queries on unmapped types

The next iteration of Entity Framework, namely Entity Framework 8, will have a new and exciting feature:

**Support raw SQL queries without defining an entity type for the result**

That means less boilerplate code! 

Until now, you had to create a mapping for types that are returned from `SqlQueryRaw`. With Entity Framework 8 this looks a bit different as a new feature helps us effectively to reduce that boilerplate. 

A small example:
```csharp
// This works from now on
context.Database.SqlQueryRaw<MyUnmappedType>(@"SELECT * FROM SomeTableOrView");
```

This is especially nice if you work with a lot of SQL views. Until now, you had to define CLR types that had the correct mapping inside the `DbContext`. 

A few notes about the limitations of that feature.
 * The entity type cannot have relationships
 * Properties are mapped by convention and mapping attributes are respected.
 * The entity types are keyless.

## Resources
 * [GitHub issue](https://github.com/dotnet/efcore/issues/10753) that tracked the feature request