EF Core 2.0 OwnsOne 列前缀

2023-12-24

使用 OwnsOne 映射复杂类型时,sql 列名称以属性名称为前缀。是否可以在映射中指定前缀名称?

这是我的映射:

e.OwnsOne(x => x.Attributes, cb =>
{
    cb.OwnsOne(a => a.Supplier);
});

我希望 sql 列以“Attr_”而不是“Attributes_”为前缀。这可能吗?


您可以编写一个扩展方法来覆盖所有列的名称;

   public static void WithPrefix<T, R>(this OwnedNavigationBuilder<T, R> builder, string prefix) where T:class where R:class
   {
      foreach (var p in builder.OwnedEntityType.GetProperties())
         p.SetColumnName($"{prefix}{p.Name}");
   }

   .OwnsOne(e => e.Address, cb => cb.WithPrefix(""));
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

EF Core 2.0 OwnsOne 列前缀 的相关文章

随机推荐