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:
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.
