c# - How to return a paged list from a property of a Domain Object using NHibernate and a Repository Pattern -
The "repository" pattern text is mediated between domains and data mapper layers. cold. So for example, maybe a repository interface and base domain objects such as
public interface stores & lt; DomainT & gt; Where DomainT: DomainObject {Get DomainT (object ID); }
Then there will be a concrete implementation
public class ThreadRepository: the store's & lt; Thread & gt; {Received public order (object id) {_session.Find return (typeof (thread), ID); }}
Now my question is, there can be several posts in the thread, like stack overflow, using 300 posts of this thread, using the above statement, I get the thread object, and I only I want to display lists of 20 items, so I will use the Post Collection Property of Thread Object, which will be all 300 due to sluggish loading, is ready for me
GetThreadPosts (object Threaded, int page Size, int index); Is it more efficient? GetThreadPostCount (object thread ID);
Or it makes relatively cheap calls in the second level of the cache, as it secures my domain model to get back 300 posts
-
What if there are 3000 or 30,000 posts, is the post archive property still valid on Thread Domain Model?
-
If it is better to get GetThreadPosts & amp; GetThreadPostCount, does this mean that a property is unnecessary on the thread object on the list?
-
Should it be that there should be a limit to pay attention to it, an object is only viable if it says that the items which are likely to be given a certain number Will not be more than
Thank you for your time,
Andrew
The way lazy loading works is to discard the execution of the database until you access it. Now if you are going to show only 30 posts on the page , While there are 30000 posts in the database that satisfy your criteria for loading your collection. Will be garbage.
The database level in my opinion paging. In this case I will remove the postal archive from the thread class and the post should be related to a thread that will allow you to create your query. Apart from this, a method will be sufficient to receive postal archives and the total number of posts:
Public IEnumerable & lt; Post & gt; GetPosts (object threadid, integer pageSize, integer index, totalPosts out) {var results = session .createMultiCriteria () .Add (GetCriteria (threadid) .SetFirstResult ((index - 1) * pageSize) .SetMaxResults (pageSize)) .Add ( GetCriteria (ThreadID) .SetProjection (Projection. RowCount ())). List (); Var number = (ILIIS) result [1]; Total post = (int) calculation [0]; Return (IILIS) result [0]). Cast & lt; Post & gt; (); } Private Detect Caracteria GetCriteria (Object Thread ID) {Return to Distracted Caracteria. & Lt; Post & gt; (). (Expression.Eq ("Thread.Id", threadID)); }
Comments
Post a Comment