首页 > 解决方案 > 审核对自有实体 Entity Framework Core 所做的更改

问题描述

我有两个实体 Employer 和 Address

public class Employer
{
    public int Code { get; set; }
    public string Initials { get; set; }
    public string Description { get; set; }
    public virtual Address Address { get; private set; }
}

public class Address
{
    public string Email { get; private set; }
    public string City { get; private set; }
    public string PostalCode { get; private set; }
    public string AddressLine { get; private set; }
}

我有一种方法可以跟踪两个实体的更改以进行审计。我想跟踪所拥有类型的更改,但我得到了

" System.InvalidOperationException: 正在使用 'Property' 方法访问实体类型 'Employer' 上的 'Address' 属性,但在模型中定义为导航属性。使用 'Reference' 或 'Collection' 方法访问导航属性。"

关于如何解决这个问题的任何想法?

标签: entity-framework-core

解决方案


推荐阅读