views:

47

answers:

1

Hello All,

I am trying to get into a project with ASP.NET MVC and NHibernate ( Newbie) and looking for faster data access from DAL.

my solution will be roughly asp.net mvc ------ Business Layer - DataAccess Layer ----------All supported by Infrastructure layer ----------------

My project is to do with classifieds and community site where faster data access is a must have.

I really like the KIGG implementation but I am not very sure if the repository pattern is suitable for faster data access.

I have looked at S#arp Architecture and it is too big for me.

On the repositories too I plan to divert from KIGG implementation and use the following for retrieving objects

IRepository {

void Add(); void Remove();

public IQueryable FindAll(Func exp) { return GetTable.Where(exp).AsQueryable(); }

}

where daily site hit might be around 10000 to 15000, is going with repository pattern with above "Find All" advisable ?

After reading for last few days on Repository pattern and also the fact that there is difference in opinion between experts themselves, I am getting more confused how repositories can be used effectively, (http://ayende.com/Blog/archive/2009/04/17/repository-is-the-new-singleton.aspx)

I know the question is vague but any advise is appreciated.

EDIT*1

I like this point about DAL: Trying to encapsulate to make things easier to work with, great. Trying to encapsulate so that you can switch OR/Ms? Won’t work, will be costly and painful.

EDIT*2

I am getting inclined towards "CQRS" pattern. It seems to be logical and from what I have been reading will make the reads faster, even though stale. Reading from Domain in terms of domain object will lead to unnecessary processing to populate AggregateRoot and then convert them to ViewModels.

Thank you, The Mar

A: 

For nHibernate, simply return the IQuerable that nHibernate LINQ creates for you after applying your expression, if needed.

What you DO NOT want to do is have nHibernate convert everything as to a list or some other objects and then use the AsQueryable on it. Simply:

return Session.Linq<T>.Where(Exp);

This may not be what you are thinking originally, but by doing this you allow the power of LINQ to work and what you do with the IQueryable to copy through all the way to the database. For example, if the caller of the method simply wanted an aggregate, the aggregate could occur on the DB server and be much more effecient rather than retrieving all the records and then performing the aggregate locally.

Remember - with IQueryable you are simply building up an expression tree until you get to a point where the tree actually needs to be excuted. When that occurs, with a DB LINQ provider like LINQ to nHibernate, anything in your expression tree is parsed and the query is formed for the database. You get the performance boost because only what you need is retireved from the DB -- no more or less.

Because it occurs on the DB, the pattern you describe should work just fine. You will not end up retrieving all entities every time, just the ones asked for.

As always, this may not fit your situation.

Bytemaster
@Bytemaster - It did help me. I am looking more into IQueryable to understand its execution. Will you suggest passing a custom QueryObject and then creating expression based on it or directly passing the expression to the repository.
TheMar