小编G_P*_*G_P的帖子

EF Core如何实施对价值对象变更的审核日志

我正在使用EF Core / .NET Core 2.1,并遵循DDD。我需要实现对我的实体的所有更改的审核日志,并且已经使用此博客文章中的代码(包括在下面的这篇文章中的相关代码中)进行了审核。该代码可以工作并跟踪对任何属性的更改,但是,当它记录对我的值对象的更改时,它仅列出新值,而没有列出旧值。

一些代码:

public class Item
{
    protected Item(){}

    //truncated for brevity

    public Weight Weight { get; private set; }
}

public class Weight : ValueObject<Weight>
{
    public WeightUnit WeightUnit { get; private set; }
    public double WeightValue { get; private set; }

    protected Weight() { }

    public Weight(WeightUnit weightUnit, double weight)
    {
        this.WeightUnit = weightUnit;
        this.WeightValue = weight;
    }
}
Run Code Online (Sandbox Code Playgroud)

以及我的上下文类中的审核跟踪代码

public class MyContext : DbContext
{
    //truncated for brevity

    public override int …
Run Code Online (Sandbox Code Playgroud)

c# domain-driven-design entity-framework entity-framework-core asp.net-core

5
推荐指数
1
解决办法
2403
查看次数