天天看点

EntityFramework用法探索(三)CodeFirst流畅API

EntityFramework用法探索(三)CodeFirst流畅API
EntityFramework用法探索(三)CodeFirst流畅API

这次没有使用属性来指定对应表名称、主键等。

使用代码创建影射,

EntityFramework用法探索(三)CodeFirst流畅API
EntityFramework用法探索(三)CodeFirst流畅API

在上下文对象中覆写OnModelCreating方法来添加影射配置,

EntityFramework用法探索(三)CodeFirst流畅API
EntityFramework用法探索(三)CodeFirst流畅API

ICustomerRepository接口和实现依然类似,

EntityFramework用法探索(三)CodeFirst流畅API
EntityFramework用法探索(三)CodeFirst流畅API

同样的测试代码,

EntityFramework用法探索(三)CodeFirst流畅API
EntityFramework用法探索(三)CodeFirst流畅API
EntityFramework用法探索(三)CodeFirst流畅API
EntityFramework用法探索(三)CodeFirst流畅API
EntityFramework用法探索(三)CodeFirst流畅API

EntityFramework用法探索系列

<a href="http://www.cnblogs.com/gaochundong/archive/2013/06/06/entityframework_usage_database_first.html">(一)DatabaseFirst</a>

<a href="http://www.cnblogs.com/gaochundong/archive/2013/06/06/entityframework_usage_code_first.html">(二)CodeFirst</a>

<a href="http://www.cnblogs.com/gaochundong/archive/2013/06/06/entityframework_usage_code_first_fluent_api.html">(三)CodeFirst流畅API</a>

<a href="http://www.cnblogs.com/gaochundong/archive/2013/06/06/entityframework_usage_repository_unitofwork.html">(四)Repository和UnitOfWork</a>

<a href="http://www.cnblogs.com/gaochundong/archive/2013/06/06/entityframework_usage_with_unity.html">(五)引入Unity</a>

<a href="http://www.cnblogs.com/gaochundong/archive/2013/06/06/entityframework_usage_static_repository.html">(六)静态Repository</a>

<a href="http://www.cnblogs.com/gaochundong/archive/2013/06/06/entityframework_usage_thread_scope.html">(七)线程安全实践</a>

<a href="http://www.cnblogs.com/gaochundong/archive/2013/06/09/entityframework_usage_transaction_scope.html">(八)事务处理</a>

<a href="https://github.com/gaochundong/WhenEntityFrameworkMeetUnity">完整代码下载</a>

本文转自匠心十年博客园博客,原文链接:http://www.cnblogs.com/gaochundong/archive/2013/06/06/entityframework_usage_code_first_fluent_api.html,如需转载请自行联系原作者

继续阅读