NHibernate 快速入门(四)使用 HQL 查询数据
2011-08-26 11:36 麦舒 阅读(626) 评论(0) 编辑 收藏 举报1、from 子句
var db = new NorthwindDataContext();
var categories = db.Session.CreateQuery("from Category")
.List<Category>();
foreach (var category in categories)
{
Console.WriteLine(category.CategoryName);
}
2、select 子句
var db = new NorthwindDataContext();
var categories = db.Session.CreateQuery("from Category as c select c.CategoryID, c.CategoryName")
.List<Category>();
foreach (var category in categories)
{
Console.WriteLine(category.CategoryName);
}
3、where 子句
var db = new NorthwindDataContext();
var categories = db.Session.CreateQuery(@"from Category as c
where c.CategoryID > 1
select c.CategoryID, c.CategoryName")
.List<Category>();
foreach (var category in categories)
{
Console.WriteLine(category.CategoryName);
}