我有一个Page
类和PageCollection
类在三方ORM框架。我可以根据参数(pageid,parentid,url等)填充PageCollection(SQL查询)。但我需要多次在ASP.NET MVC网站(Sitemap,身份验证)中使用这些数据,所以我选择一次加载所有页面并引用(全局)集合。.NET - 数据库实体的高效收集?
GlobalClass.Pages //is PageCollection containing all pages
我现在已经创建了返回基于之前(的pageid,parentId的,URL等)提到的参数的临时子集合或单一实体的功能。
GlobalClass.Pages.GetByPageId(id) //returns single page entity
GlobalClass.Pages.GetByParentId(parentid) //returns subcollection
但是网站速度很慢。
这是怎么走的?
- 缓存中的子集(
GetByParent()
)? - 为集合创建内部哈希查找表?
- 别的东西...?
Namespace BLL
Public Class PageCollection
Inherits CustomCollectionBase
Public Sub New()
End Sub
Public Sub LoadByParent(ByVal PagParent As Integer)
If PagParent = 0 Then
Me.whereAdd('parent IS NULL')
Else
Me.whereAdd('parent = ' & PagParent.ToString())
End If
Me.Load(Me.data)
End Sub
Public Function GetBySiteMapNode(ByVal node As SiteMapNode) As BLL.Page
Return Me.GetByUrl(node.Url)
End Function
Public Function GetById(ByVal id As Integer) As BLL.Page
For Each p In Me
If p.PagAutoKey = id Then Return p
Next
Return Nothing
End Function
Public Function GetByUrl(ByVal url As String) As BLL.Page
For Each p In Me
If p.Url = url Then Return p
Next
Return Nothing
End Function
Public Function GetByParent(ByVal parent As Integer) As BLL.PageCollection
Dim pc As New PageCollection
For Each p In Me
If p.PagParent = parent Then pc.Add(p)
Next
Return pc
End Function
End Class
End Namespace
这是一个asp.net应用程序吗? – 2010-01-15 15:48:31
是的,一些非常重要的信息没有给出:) – Ropstah 2010-01-15 15:59:58
什么是慢? GetBy方法比预期的要慢吗?如果GetBy方法碰到数据库而不是全局集合,它们会更快吗? – 2010-01-15 16:10:59