项目学习之OnModelCreating

在EF Code First中,OnModelCreating方法用于在上下文初始化时进一步配置模型。默认实现不执行任何操作,但可以通过重写该方法并使用Fluent API来调整实体与表的映射,例如禁用一对一或多对一的级联删除。了解更多详情可以参考MSDN相关文章。
摘要由CSDN通过智能技术生成

摘自MSDN:

This method is called when the model for a derived context has been initialized, but before the model has been locked down and used to initialize the context. The default implementation of this method does nothing, but it can be overridden in a derived class such that the model can be further configured before it is locked down.

在Code First方法中,还可以通过Fluent API的方式来处理实体与数据表之间的映射关系。要使用Fluent API必须在构造自定义的DbContext时,重写OnModelCreating方法,在此方法体内调用Fluent API。

 1  public class OceanSampleDatabase : DbContext, IDatabase
 2  {    

        //配置移除多重级联删除
        modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConve

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值