天天看點

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,如需轉載請自行聯系原作者

繼續閱讀