EF Core ComplexType Attribute

Starting from EF Core 8, it's now possible to set a class or a structure as a Complex Type. The following example specifies that the Address class should be considered as a complex type:

language-csharp
|
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

public class Order
{
    public int OrderId { get; set; }
    public DateTime OrderDate { get; set; }
    [Required]
    public Address ShippingAddress { get; set; }
    [Required]
    public Address BillingAddress { get; set; }
    //... other order-related properties
}

[ComplexType]
public class Address
{
    public string Street { get; set; }
    public string City { get; set; }
    public string State { get; set; }
    public string Country { get; set; }
    public string PostalCode { get; set; }
}

One particularity of the complex type is that you also have to mark the complex property as Required

Fluent API

The Fluent API equivalent to the ComplexType attribute is the ComplexProperty method.

🔄 Synchronize Your Data in One Step

Need your database to match an incoming list? BulkSynchronize inserts new records, updates existing ones, and deletes missing ones.

Explore BulkSynchronize →

Date Modified: 2025-07-11
Author:

Edit this page in GitHub

Got any EF Core Question?