Skip to content

Support for nested owned types #167

Closed
@dweggemans

Description

@dweggemans

I am trying to bulk insert entities with a nested owned type.

For example this slighly modified hierarchy taken from the test project:

public class ChangeLog
{
    public int ChangeLogId { get; set; }

    public string Description { get; set; }

    public Audit Audit { get; set; }
}

[Owned]
public class Audit
{
    [Column(nameof(ChangedBy))] // for setting custom column name, in this case prefix OwnedType_ ('Audit_') removed, so column would be only ('ChangedBy')
    public string ChangedBy { get; set; } // default Column name for Property of OwnedType is OwnedType_Property ('Audit_ChangedBy')

    public bool IsDeleted { get; set; }

    [NotMapped] // alternatively in OnModelCreating(): modelBuilder.Entity<Audit>().Ignore(a => a.ChangedTime);
    public DateTime? ChangedTime { get; set; }

    // Added owned type property
    public AuditExtended AuditExtended { get; set; }
}

[Owned]
public class AuditExtended
{
    [Required] // Added required so if fails on null insert
    public string CreatedBy { get; set; }

    [NotMapped]
    public DateTime? CreatedTime { get; set; }

    [NotMapped]
    public string Remark { get; set; }
}

This fails because the it tries to insert null for the AuditExtended.CreatedBy property. Any chance of adding support for nested owned types?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions