tôi có loại phức tạp cho các lĩnh vực Kiểm toánEF-Code đầu tiên sở hữu phím điều hướng nước ngoài tại phức tạp kiểu
loại phức tạp của tôi:
[ComplexType]
public class AuditData {
[Column("CreatorUserId")]
public int? CreatorUserId { get; set; }
public DateTime? CreationTime { get; set; }
[Column("ModifierUserId")]
public int? ModifierUserId { get; set; }
public DateTime? ModificationTime { get; set; }
}
Entity cơ sở của tôi (tất cả khác inherti này) có tài sản AuditData:
public abstract class Entity : IEntity, IAuditedEntity, INotifiedDbContextBeforeSave
{
// Summary:
// Unique identifier for this entity.
public int Id { get; set; }
public bool IsActive { get; set; }
public int Old_Id { get; set; }
public string Old_TableName { get; set; }
[Timestamp]
public byte[] RowVersion { get; set; }
public AuditData AuditData { get; set; }
// can this 2 lines below work as navigation property with foreign key in complex type
public virtual User CreatorUser { get; set; }
public virtual User ModifierUser { get; set; }
//... other fields
}
Tôi có 2 thuộc tính điều hướng CreatorUser and ModifierUser. Tôi biết bạn không thể có bất động sản chuyển hướng trong complexType nhưng có thể sở hữu chuyển hướng của tôi về thực thể được ánh xạ với khóa ngoại trong complexType
cái gì đó như:
[ForeignKey("CreatorUserId")] // --> should point to AuditData.CreatorUserId
public virtual User CreatorUser { get; set; }
becouse CreatorUserId sẽ được sở hữu trong mỗi thực thể nhưng EF không phải là ý thức về nó. Mybe có giải pháp trong API thông thạo?