设为首页 加入收藏

TOP

19.翻译系列:EF 6中定义自定义的约定【EF 6 Code-First约定】(二)
2019-09-17 19:07:03 】 浏览:59
Tags:19. 翻译 系列 定义 约定 Code-First
vention : Convention {
public PKConvention() { .Properties() .Where(p => p.Name == p.DeclaringType.Name + "_ID") .Configure(p => p.IsKey()); } }

添加完自定义的类,然后在OnModelCreating方法中这样用:

protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Conventions.Add<PKConvention>(); }

 

模型约定

 

模型约定是基于模型元数据的。这里有关于CSDL和SSDL的约定,创建一个类,实现CSDL约定中的IConceptualModelConvention 接口,或者实现SSDL约定中的IStoreModelConvention 接口。

想要了解更多EF 6 自定义约定相关的,可以看看这篇文章: Custom Convention in EF 6 。

 

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇WebService连接winfrom简单实例 下一篇C#中简单操作SQLserver数据库(AD..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目