DataReader 从数据库中检索只读、只进的数据流用法
1.DataReader的用法:
DataReader 从数据库中检索只读、只进的数据流。查询结果在查询执行时返回,在并存储在客户端的网络缓冲区中,
直到您使用 DataReader 的 Read 方法对它们发出请求。 使用 DataReader 可以提高应用程序的性能,
原因是它只要数据可用就立即检索数据,并且(默认情况下)一次只在内存中存储一行,减少了系统开销。
例子见上一篇即可,说说使用DataReader的心得,在做项目中,有时候一个实体类中的字段又是另外一个实体雷,
存在外键的关系。如下实体类源码 中就有2个这样的关系(高亮代码):
using System;
using System.Collections.Generic;
using System.Text;
namespace BookShop.Model
{
[Serializable]
public class Book
{
/// <summary>
/// 图书编号
/// </summary>
private int id;
public int Id
{
get { return id; }
set { id = value;
}
}
/// <summary>
/// 图书标题
/// </summary>
private string title;
public string Title
{
get { return title; }
set { title = value;
}
}
/// <summary>
/// 图书作者
/// </summary>
private string author;
public string Author
{
get { return author; }
set { author = value;
}
}
/// <summary>
/// 图书出版社
/// </summary>
private Publisher publisher;
public Publisher Publisher
{
get { return publisher;
}
set { publisher = value;
}
}
/// <summary>
/// 图书出版日期
/// </summary>
private DateTime publishDate;
public DateTime PublishDate
{ get { return publishDate;
}
set { publishDate = value;
}
}
/// <summary>
/// 图书ISBN编号
/// </summary>
private string isbn;
public string Isbn
{
get { return isbn;
}
set { isbn = value;
}
}
/// <summary>
/// 图书总字数
/// </summary>
private int wordsCount;
public int WordsCount
{
get
{ return wordsCount; }
set { wordsCount = value; }
}
/// <summary>
/// 图书价格
/// </summary>
private decimal unitPrice;
public decimal UnitPrice
{
get { return unitPrice; }
set { unitPrice = value; }
}
/// <summary>
/// 图书描述
/// </summary>
private string contentDescription;
public string ContentDescription
{
get { return contentDescription; }
set { contentDescription = value; }
}
/// <summary>
/// 图书作者描述
/// </summary>
private string authorDescription;
public string AuthorDescription
{
get { return authorDescription; }
set { authorDescription = value; }
}
/// <summary>
/// 图书作者评语
/// </summary>
private string editorComment;
public string EditorComment
{
get { return editorComment; }
set { editorComment = value; }
}
/// <summary>
/// 图书目录
/// </summary>
private string toc;
public string Toc
{
get { return toc; }
set { toc = value; }
}
/// <summary>
/// 图书的分类
/// </summary>
private Category category;
public Category Category
{
get { return category; }
set { category = value; }
}
/// <summary>
/// 图书点击
- 51.la

招生简章


