Код: Выделить всё
[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("_","_");
}
Но когда я добавил ComplexType внутри Owned< /code>, например:
Код: Выделить всё
//(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;
}
Я пытался вручную указать, что это сложное свойство, используя такой метод Fluent, но, похоже, это не помогло существуют там:
Код: Выделить всё
builder.Entity(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.
}
);
}
Код: Выделить всё
Note: Migration is generated against SQLite.
Подробнее здесь: https://stackoverflow.com/questions/791 ... d-property