客户端生成值的EF Core批注

问题描述

我想将代码优先类(EF Core 3.1)设置为使用值生成器(Microsoft.EntityFrameworkCore.ValueGeneration.ValueGenerator生成值。对我来说很重要的是,这些值是在客户端而不是数据库生成的。另外,我想使用注释而不是流利的API,因为我需要使用派生类型。像这样的东西:

public class typeX
{
  [Key]
  [some-annotation?] // This is where I want to add my annotation
  public string MyKey { get; set; }

  [some-other-annotation?] // This is where I want to add my annotation
  public string OtherData { get; set; }
}

public class derivedA : typeX
{
}

public class derivedB : typeX
{
}

我想注释MyKeyOtherData,以便它们使用生成器(例如GuidValueGeneratorMyCustomValueGenerator)。我想我知道如何使用 fluent API (尽管大多数示例都是针对数据库生成的),但我找不到使用注释的方法。这可能吗?在某些情况下,我想在创建时生成值,而在另一些情况下,我想在创建时生成值。

谢谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)