entity-framework-core - Fluent-API 的自定义 DataAnnotations 属性
问题描述
我正在将一个项目从 EF6 移植到 EF7 Core,并且我正在将所有带有 DataAnnotationtions 的类转换为 FluentAPI。
在项目中,我广泛使用了自定义数据注释属性。我需要转换:
[Required, MaxLength(Consts.DbLength.OriginName)]
[FrontendEditable]
public string OriginName { get; set; }
其中 [FrontendEditable] 类似于:
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Enum, AllowMultiple = false, Inherited = false)]
public class FrontendEditableAttribute : Attribute
{
public FrontendEditableAttribute()
{
}
我想将其转换为 modelBuilder 中的 Fluent API,例如:
modelBuilder.Entity<Origin>(e =>
{
e.Property(oN => oN.OriginName).IsRequired();
e.Property(oN => oN.OriginName).HasColumnType("NVARCHAR");
e.Property(oN => oN.OriginName).HasMaxLength(50);
});
这是为了使 db 的某些字段仅可从 FrontEnd 编辑并锁定。
任何建议将不胜感激。
解决方案
推荐阅读
- python-3.x - 熊猫在彼此附近更改日期
- java - 如何仅从日期单元格中检索日期
- django - Angular 和 Django 文件上传:禁止 (403) CSRF 验证失败。请求中止
- mysql - MySQL 8 按数组中的值搜索 JSON 键
- javascript - 组件生命周期的“渲染”阶段
- python - 如何绕过 Python 中的列表别名
- bash - 如何使用 Mac 终端从不同长度的文件名中删除除最后 12 个字符之外的所有字符?
- azure-service-fabric - Service Fabric 是否提供分布式事务机制?
- java - 如何从firebase实时数据库中检索用户名
- python - 在 Windows 上使用 tee 时如何保留 python colorama 颜色输出