FluentData輕量級.NET ORM持久化技術(shù)詳解03- Mapping數(shù)據(jù)模型映射(視頻+教程)

一、課程導學

當前市面上的 ORM 框架,如 Entity Framework 和 NHibernate,都過于復雜而且難于學習。此外,由于這些框架自身抽象的查詢語言以及從數(shù)據(jù)庫到 .NET 對象的映射太過麻煩,導致它們生成的 SQL 都很低效。

FluentData 另辟蹊徑,它是一個輕量級框架,擁有簡單的 fluent API 并且很容易學會?,F(xiàn)在越來越多的.NET企業(yè)級開發(fā)選擇后端的ORM采用FluentData框架。

本系列教程將會從最基本的FluentData安裝、配置開始講起,一步步深入API使用與詳細案例與性能優(yōu),全程會以【視頻+教程】方式呈現(xiàn),原系我本人的一某在線網(wǎng)站的收費課程,現(xiàn)打算全部公開出去。具體教程公開計劃如下:

01_FluentData快速入門

02_FluentData進階-Query查詢

03_FluentData進階-Mapping

04_FluentData進階-多結(jié)果集&分頁查詢

05_FluentData進階-Insert的三種方式

06_FluentData進階-InsertAndUpdateBuilder&Delete操作

07_FluentData高級-如何操作存儲過程

08_FluentData高級-使用事務(wù)與Entity Factory

09_FluentData高級-綜合示例

我會持續(xù)本專題,如你想要獲取本套課程課件,源碼可在本文后留言給我,我收到后會第一時間回復。你的支持是我持續(xù)寫作的動力,如你覺得對你有幫助,歡迎點贊,收藏,轉(zhuǎn)發(fā),評論,打賞,謝謝!

二、視頻

本章內(nèi)容:FluentData輕量級.NET ORM持久化技術(shù)詳解03- Mapping數(shù)據(jù)模型映射(視頻+教程)

01、視頻鏈結(jié):FluentData輕量級.NET ORM持久化技術(shù)詳解03- Mapping數(shù)據(jù)模型映射(上)


FluentData輕量級.NET ORM持久化技術(shù)詳解03- Mapping數(shù)據(jù)模型映射(上) - 騰訊視頻

02、視頻鏈結(jié):FluentData輕量級.NET ORM持久化技術(shù)詳解03- Mapping數(shù)據(jù)模型映射(下)


FluentData輕量級.NET ORM持久化技術(shù)詳解03- Mapping數(shù)據(jù)模型映射(下) - 騰訊視頻

03、視頻鏈結(jié):FluentData輕量級.NET ORM持久化技術(shù)詳解03- 多結(jié)果集&分頁技術(shù)


FluentData輕量級.NET ORM持久化技術(shù)詳解03- 多結(jié)果集&分頁技術(shù)- 騰訊視頻


三、配套文字教程

3.1、Mapping(映射)

3.1.1、 自動匹配:在數(shù)據(jù)庫和.NET 對象一一對應(yīng)Listproducts = Context.Sql(@"select *from Product").QueryMany();

3.1.2、自動映射到自定義的集合ProductionCollection products = Context.Sql("select * from Product").QueryMany();

3.1.3、 Automapping - Mismatch between the database and the .NET object, use the alias keyword in SQL:Weakly typed:Listproducts = Context.Sql(@"select p.*,c.CategoryId as Category_CategoryId,c.Name as Category_Namefrom Product pinner join Category c on p.CategoryId = c.CategoryId").QueryMany();

3.1.4、 Custom mapping using dynamic:Listproducts = Context.Sql(@"select * from Product").QueryMany(Custom_mapper_using_dynamic);

public void Custom_mapper_using_dynamic(Product product, dynamic row)

{

product.ProductId = row.ProductId;

product.Name = row.Name;

}

3.1.5、Custom mapping using a datareader:Listproducts = Context.Sql(@"select * from Product").QueryMany(Custom_mapper_using_datareader);public void Custom_mapper_using_datareader(Product product, IDataReader row){product.ProductId = row.GetInt32("ProductId");product.Name = row.GetString("Name");}或者:如果你有一個比較復雜的類型你需要控制它的創(chuàng)建的話,那么你可以使用QueryComplexMany/QueryComplexSingle方法來實現(xiàn)var products = new List();Context.Sql("select * from Product").QueryComplexMany(products, MapComplexProduct);private void MapComplexProduct(IListproducts, IDataReader reader)

{

var product = new Product();

product.ProductId = reader.GetInt32("ProductId");

product.Name = reader.GetString("Name");

products.Add(product);

}

3.2、多結(jié)果集(Multiple result sets)

FluentData supports multiple resultsets. This allows you to do multiple queries in a single database call. When this feature is used it's important to wrap the code inside a using statement as shown below in order to make sure that the database connection is closed.using (var command = Context.MultiResultSql){Listcategories = command.Sql(@"select * from Category;select * from Product;").QueryMany();Listproducts = command.QueryMany();

}

The first time the Query method is called it does a single query against the database. The second time the Query is called, FluentData already knows that it's running in a multiple result set mode, so it reuses the data retrieved from the first query.

3.3、分頁(Select data and Paging)

A select builder exists to make selecting data and paging easy:Listproducts = Context.Select("p.*, c.Name as Category_Name")

.From(@"Product p

inner join Category c on c.CategoryId = p.CategoryId")

.Where("p.ProductId > 0 and p.Name is not null")

.OrderBy("p.Name")

.Paging(1, 10).QueryMany();

By calling Paging(1, 10) then the first 10 products will be returned.

四、結(jié)束

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容