<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/ef-core-union-types-a-practical-guide-l6bkq4jyy" -->

---
title: EF Core Union Types: A Practical Guide | daily.dev
description: A practical walkthrough of persisting C# union types (coming in C# 15) with EF Core, which natively cannot handle value-typed union types as entities. The...
canonical: https://daily.dev/posts/ef-core-union-types-a-practical-guide-l6bkq4jyy
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: EF Core Union Types: A Practical Guide | daily.dev
og:description: A practical walkthrough of persisting C# union types (coming in C# 15) with EF Core, which natively cannot handle value-typed union types as entities. The...
og:url: https://daily.dev/posts/ef-core-union-types-a-practical-guide-l6bkq4jyy
og:image: https://api.daily.dev/og/posts/L6BKq4Jyy.png
og:image:alt: EF Core Union Types: A Practical Guide
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.

# EF Core Union Types: A Practical Guide

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

## Summary

A practical walkthrough of persisting C# union types (coming in C# 15) with EF Core, which natively cannot handle value-typed union types as entities. The approach introduces a companion data model record that flattens all possible union variant fields into nullable columns on the containing entity's table, using a hardcoded string discriminator. EF Core maps this via ComplexProperty on a private backing field, while explicit two-way conversion methods bridge the rich domain model and the flat relational representation. The result lets application code work entirely with the union type while EF Core transparently handles 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=7u_WO3fEPLc>

## 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

---

Tags: [#c#](https://daily.dev/tags/c#)

[View this post on daily.dev](https://daily.dev/posts/ef-core-union-types-a-practical-guide-l6bkq4jyy)

```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":"EF Core Union Types: A Practical Guide","url":"https://daily.dev/posts/ef-core-union-types-a-practical-guide-l6bkq4jyy","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/ef-core-union-types-a-practical-guide-l6bkq4jyy"},"datePublished":"2026-07-14T06:35:41.503Z","dateModified":"2026-07-14T06:35:59.832Z","description":"A practical walkthrough of persisting C# union types (coming in C# 15) with EF Core, which natively cannot handle value-typed union types as entities. The...","image":"https://i.ytimg.com/vi/7u_WO3fEPLc/sddefault.jpg","thumbnailUrl":"https://i.ytimg.com/vi/7u_WO3fEPLc/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/ef-core-union-types-a-practical-guide-l6bkq4jyy","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":2},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"c#","timeRequired":"PT12M","video":{"@type":"VideoObject","name":"EF Core Union Types: A Practical Guide","description":"A practical walkthrough of persisting C# union types (coming in C# 15) with EF Core, which natively cannot handle value-typed union types as entities. The...","thumbnailUrl":"https://i.ytimg.com/vi/7u_WO3fEPLc/sddefault.jpg","uploadDate":"2026-07-14T06:35:41.503Z","duration":"PT12M","url":"https://api.daily.dev/r/L6BKq4Jyy","embedUrl":"https://www.youtube.com/embed/7u_WO3fEPLc"}}
{"@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":"EF Core Union Types: A Practical Guide"}]}
```

