2

I'm using ComplexTypeAttribute for some data columns that I want to group together like:

[ComplexType]
public record TrashData(DateTime? Value)
{
    public Identity By { get; init; } = Identity.Unknown;

    private string _reason = string.Empty;
    public string? Reason
    {
        get => _reason;
        init => _reason = string.IsNullOrWhiteSpace(value) ? string.Empty : value;
    }

    private static readonly TrashData _available = new TrashData((DateTime?)null);
    public static TrashData Available => _available;
}
[ComplexType]
public record Identity(string IdKind = "GUID", string? Value = null)
{
  public static readonly Identity Unknown = new("_","_");
}

I found no issue adding ComplexType inside another one.

But when I added a ComplexType inside an Owned property like the following:

//(I'm using Asp Identity)
public class User : IdentityUser
{
    public required UserMetaData MetaData { get; set; } = new(default);
}
[Owned]
public record UserMetaData(string Id)
{
    public TrashData Trashed_ { get; set; } = TrashData.Available;
}

I had build issues after generating migration:

'OwnedNavigationBuilder' does not contain a definition for 'ComplexProperty'

I tried to manually specify this property is complex using Fluent Method like this, but it doesn't seem to exist there:

builder.Entity<User>(e =>
{
//  e.ComplexProperty(x => x.MetaData.Trashed_); // Can call ComplexProperty

    e.OwnsOne(
        x => x.MetaData,
        o =>
        {
            o.WithOwner().HasPrincipalKey(x => x.Id).HasForeignKey(x => x.Id);
            // o.ComplexProperty(x => x.Trashed_); // Can't call complex property here.
        }
    );
}

So does EF Core 8 support complex type inside owned property, or not yet?

Note: Migration is generated against SQLite.

1 Answer 1

2

After some research, .Net 8 and .Net 9 currently don't support complex types under owned properties. And I think it's not even planned for .Net 10.

So use other methods with owned properties, like nested ones, or don't use it at all.

There is currently an open feature request on Entity Framework Core with this issue, but there is no planned release addressing it as of November 2025.

Sign up to request clarification or add additional context in comments.

1 Comment

This still appears to be an issue. Strange that I can't find any documentation about it. Though I did find a GitHub issue for it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.