EF Core 2.0 OwnsOne column prefix

前端 未结 2 397
心在旅途
心在旅途 2021-02-10 04:15

When using OwnsOne to map complex types, the sql column name is prefixed with the attribute name. Is it possible to specify the prefix name in the mapping?

This is my ma

2条回答
  •  深忆病人
    2021-02-10 04:44

    You could write an extension method to override the names of all columns;

       public static WithPrefix(this OwnedNavigationBuilder 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(""));
    

提交回复
热议问题