首先,我在LinqToNHibernate中使用了Fluent NHibernate。挂载在惰性加载查询上的NHibernate
我有一个查询,根据用户输入的数据对表进行搜索。因此,举例来说,我在做这样的事情:
'build the initial query that we will filter--this is lazy loaded
Dim results As IEnumerable(Of Customers) = Me.GetCustomers()
'filter by owner name
If String.IsNullOrEmpty(OwnerName) = False Then
results = results.Where(Function(s) s.Name.Contains(OwnerName))
End If
'execute query
results = results.ToList()
所以基本上如果用户想通过名称来搜索我的sql语句建立一个where语句。我在映射中使用了所有惰性配置,因此查询不应检索项目,直到调用“ToList()”。问题在于NHibernate挂在这个声明上。起初我以为这是因为db中有很多记录(大约500,000)。
但我改变了我在哪里过滤的结果,该行:
results = SessionFactoryProvider.SessionFactory.CurrentSession.Linq(Of Customer).Where(Function(c) c.Name.Contains(OwnerName))
而且它非常快的工作。但我似乎无法弄清楚为什么。有任何想法吗?
谢谢;这工作完美:)我认为我的问题是我的返回类型是IEnumerable在第一行而不是IQueryable。我将来会知道。 – Austin 2009-12-14 22:17:09