<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/discriminated-unions-over-union-types-the-ef-core-viewpoint-7ncinnpfd" -->

---
title: Discriminated Unions Over Union Types: The EF Core Viewpoint
description: C# 15 is introducing union types, but EF Core has no announced support for persisting them. This walkthrough demonstrates how to model a discriminated union...
canonical: https://daily.dev/posts/discriminated-unions-over-union-types-the-ef-core-viewpoint-7ncinnpfd
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Discriminated Unions Over Union Types: The EF Core Viewpoint | daily.dev
og:description: C# 15 is introducing union types, but EF Core has no announced support for persisting them. This walkthrough demonstrates how to model a discriminated union...
og:url: https://daily.dev/posts/discriminated-unions-over-union-types-the-ef-core-viewpoint-7ncinnpfd
og:image: https://api.daily.dev/og/posts/7NcINNPFd.png
og:image:alt: Discriminated Unions Over Union Types: The EF Core Viewpoint
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Discriminated Unions Over Union Types: The EF Core Viewpoint

**[Zoran Horvat](https://daily.dev/sources/zoranhorvat)** · 15 min read · 1 upvotes · 0 comments

## Summary

C# 15 is introducing union types, but EF Core has no announced support for persisting them. This walkthrough demonstrates how to model a discriminated union using a hierarchy of C# records and configure EF Core to persist it using the table-per-hierarchy (TPH) strategy — stored directly in the parent entity's table rather than a separate joined table. The approach avoids manual type conversions, eliminates JOIN queries, and handles polymorphic updates cleanly. Key steps include defining an abstract base record with concrete subtypes, configuring a discriminator column, and using EF Core's owned-entity mapping to co-locate the hierarchy columns in the Transfers table. The result is a domain-friendly model with no database JOINs and full EF Core-managed persistence.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.youtube.com/watch?v=VK7oWg9dTMc>

## Questions this post answers

### How can I persist a discriminated union (hierarchy of records) in the same table as its parent entity using EF Core?

Map the record hierarchy with EF Core's table-per-hierarchy strategy, then configure the relationship between the parent entity and the union as one-to-one instead of one-to-many, using the parent's own Id as the shared key. Remove any shadow Id property on the union so its identity resolves to the parent row, eliminating the need for a separate table or JOIN when querying.

_For teams mapping domain records onto relational schemas, daily.dev surfaces EF Core patterns like this one._

### Why does querying a discriminated union stored in its own EF Core table require a JOIN?

A JOIN appears because the discriminated union hierarchy was mapped into its own table with a foreign key relationship from the parent entity, rather than being merged into the parent's table. Fixing this requires collapsing the table-per-hierarchy mapping into the same table as the containing entity and switching the relationship to one-to-one, which removes the JOIN entirely.

_Developers optimizing relational query performance can track EF Core mapping techniques like this via daily.dev._

## Similar posts on daily.dev

- [Working union types into C\#](https://daily.dev/posts/working-union-types-into-c--n1rhxnbqf) · Atomic Spin · 0 upvotes · 0 comments
- [C\# 15 Union Types and Closed Hierarchies in .NET 11](https://daily.dev/posts/c-15-union-types-and-closed-hierarchies-in-net-11-lxpnwfzfk) · We Are .NET · 0 upvotes · 0 comments

---

Tags: [#.net](https://daily.dev/tags/.net), [#c#](https://daily.dev/tags/c#), [#domain-driven-design](https://daily.dev/tags/domain-driven-design)

[View this post on daily.dev](https://daily.dev/posts/discriminated-unions-over-union-types-the-ef-core-viewpoint-7ncinnpfd)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Discriminated Unions Over Union Types: The EF Core Viewpoint","url":"https://daily.dev/posts/discriminated-unions-over-union-types-the-ef-core-viewpoint-7ncinnpfd","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/discriminated-unions-over-union-types-the-ef-core-viewpoint-7ncinnpfd"},"datePublished":"2026-07-21T06:36:13.834Z","dateModified":"2026-09-14T08:03:09.032Z","description":"C# 15 is introducing union types, but EF Core has no announced support for persisting them. This walkthrough demonstrates how to model a discriminated union...","image":"https://i.ytimg.com/vi/VK7oWg9dTMc/sddefault.jpg","thumbnailUrl":"https://i.ytimg.com/vi/VK7oWg9dTMc/sddefault.jpg","isAccessibleForFree":true,"articleSection":"Zoran Horvat","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Zoran Horvat","logo":"https://media.daily.dev/image/upload/s--TnVKcFzX--/f_auto/v1737645875/logos/zoranhorvat","url":"https://daily.dev/sources/zoranhorvat"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/discriminated-unions-over-union-types-the-ef-core-viewpoint-7ncinnpfd","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":".net,c#,domain-driven-design","timeRequired":"PT15M","video":{"@type":"VideoObject","name":"Discriminated Unions Over Union Types: The EF Core Viewpoint","description":"C# 15 is introducing union types, but EF Core has no announced support for persisting them. This walkthrough demonstrates how to model a discriminated union...","thumbnailUrl":"https://i.ytimg.com/vi/VK7oWg9dTMc/sddefault.jpg","uploadDate":"2026-07-21T06:36:13.834Z","duration":"PT15M","url":"https://api.daily.dev/r/7NcINNPFd","embedUrl":"https://www.youtube.com/embed/VK7oWg9dTMc"}}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Zoran Horvat","item":"https://daily.dev/sources/zoranhorvat"},{"@type":"ListItem","position":3,"name":"Discriminated Unions Over Union Types: The EF Core Viewpoint"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/discriminated-unions-over-union-types-the-ef-core-viewpoint-7ncinnpfd#faq","mainEntity":[{"@type":"Question","name":"How can I persist a discriminated union (hierarchy of records) in the same table as its parent entity using EF Core?","acceptedAnswer":{"@type":"Answer","text":"Map the record hierarchy with EF Core's table-per-hierarchy strategy, then configure the relationship between the parent entity and the union as one-to-one instead of one-to-many, using the parent's own Id as the shared key. Remove any shadow Id property on the union so its identity resolves to the parent row, eliminating the need for a separate table or JOIN when querying. For teams mapping domain records onto relational schemas, daily.dev surfaces EF Core patterns like this one."}},{"@type":"Question","name":"Why does querying a discriminated union stored in its own EF Core table require a JOIN?","acceptedAnswer":{"@type":"Answer","text":"A JOIN appears because the discriminated union hierarchy was mapped into its own table with a foreign key relationship from the parent entity, rather than being merged into the parent's table. Fixing this requires collapsing the table-per-hierarchy mapping into the same table as the containing entity and switching the relationship to one-to-one, which removes the JOIN entirely. Developers optimizing relational query performance can track EF Core mapping techniques like this via daily.dev."}}]}
```

