【发布时间】:2012-02-01 22:07:47
【问题描述】:
我有以下关系
class Author
{
int Id;
}
class Publisher
{
int Id;
}
class Book
{
Publisher Publisher;
Author Author;
DateTime PublishDate;
}
我想优化以下查询:
foreach (Publisher)
{
foreach (Author)
{
session.Query<Book>()
.Where(x=> x.Author.Id == Author.Id && x.Publisher.Id ==Publisher.Id)
.OrderByDescending(x=> x.PublishDate)
.Take(5);
}
}
我意识到这段代码在性能方面很糟糕,我该如何改进它并在更少的查询中获得相同的结果?
非常感谢!
【问题讨论】:
标签: c# nhibernate session optimization