-
Notifications
You must be signed in to change notification settings - Fork 860
自定义特性
28810 edited this page Oct 14, 2019
·
16 revisions
以下的示例代码,FreeSql 使用 EFCore 的实体特性。
fsql.CodeFirst.ConfigEntity<ModelAopConfigEntity>(a => a.Property(b => b.pkid).IsPrimary(true));
fsql.Aop.ConfigEntity = (s, e) => {
var attr = e.EntityType.GetCustomAttributes(typeof(System.ComponentModel.DataAnnotations.Schema.TableAttribute), false).FirstOrDefault() as System.ComponentModel.DataAnnotations.Schema.TableAttribute;
if (attr != null)
e.ModifyResult.Name = attr.Name; //表名
//e.ModifyIndexResult.Add(new IndexAttribute("idx_xx", "Title")); //索引
};
fsql.Aop.ConfigEntityProperty = (s, e) => {
if (e.Property.GetCustomAttributes(typeof(System.ComponentModel.DataAnnotations.KeyAttribute), false).Any())
e.ModifyResult.IsPrimary = true; //主键
};
[System.ComponentModel.DataAnnotations.Schema.Table("xxx")]
class ModelAopConfigEntity {
[System.ComponentModel.DataAnnotations.Key]
[Column(IsPrimary = false)]
public int pkid { get; set; }
}
数据库特性 > 实体特性 > FluantApi(配置特性) > Aop(配置特性)