一、課程導(dǎo)學(xué)
當(dāng)前市面上的 ORM 框架,如 Entity Framework 和 NHibernate,都過于復(fù)雜而且難于學(xué)習(xí)。此外,由于這些框架自身抽象的查詢語言以及從數(shù)據(jù)庫到 .NET 對象的映射太過麻煩,導(dǎo)致它們生成的 SQL 都很低效。
FluentData 另辟蹊徑,它是一個輕量級框架,擁有簡單的 fluent API 并且很容易學(xué)會。現(xiàn)在越來越多的.NET企業(yè)級開發(fā)選擇后端的ORM采用FluentData框架。
本系列教程將會從最基本的FluentData安裝、配置開始講起,一步步深入API使用與詳細(xì)案例與性能優(yōu),全程會以【視頻+教程】方式呈現(xiàn),原系我本人的一某在線網(wǎng)站的收費課程,現(xiàn)打算全部公開出去。具體教程公開計劃如下:
01_FluentData快速入門
02_FluentData進(jìn)階-Query查詢
03_FluentData進(jìn)階-Mapping
04_FluentData進(jìn)階-多結(jié)果集&分頁查詢
05_FluentData進(jìn)階-Insert的三種方式
06_FluentData進(jìn)階-InsertAndUpdateBuilder&Delete操作
07_FluentData高級-如何操作存儲過程
08_FluentData高級-使用事務(wù)與Entity Factory
09_FluentData高級-綜合示例
我會持續(xù)本專題,如你想要獲取本套課程課件,源碼可在本文后留言給我,我收到后會第一時間回復(fù)。你的支持是我持續(xù)寫作的動力,如你覺得對你有幫助,歡迎點贊,收藏,轉(zhuǎn)發(fā),評論,打賞,謝謝!
二、視頻
本章內(nèi)容:FluentData輕量級.NET ORM持久化技術(shù)詳解03- Mapping數(shù)據(jù)模型映射(視頻+教程)
01、視頻鏈結(jié):FluentData輕量級.NET ORM持久化技術(shù)詳解03- Mapping數(shù)據(jù)模型映射(上)
02、視頻鏈結(jié):FluentData輕量級.NET ORM持久化技術(shù)詳解03- Mapping數(shù)據(jù)模型映射(下)
03、視頻鏈結(jié):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");}或者:如果你有一個比較復(fù)雜的類型你需要控制它的創(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.