In the past few months I've learned alot about Linq-To-Entities and the 3-tier architecture with a DAO/DAL/Repository. Now I've a few things in my mind that keeps bugging me. I've those three questions that you'll see below.
There are alot of ways to make the repository work but what way is "the" way of making the repository work in ways of performance.
1) Initialize a datacontext in the constructor
public class Repository : IRepository
{
private Datacontext context;
public Repository()
{
context = new Datacontext();
}
public IList<Entity> GetEntities()
{
return (from e in context.Entity
select e).ToList();
}
}
2) Use "Using"
public class Repository : IRepository
{
public IList<Entity> GetEntities()
{
using (Datacontext context = new Datacontext())
{
return (from e in context.Entity
select e).ToList();
}
}
}
3) In another way (please comment)
I'll put your suggestion here for others to comment
Also it seems some people say the repository should return an IQueryable to the businesslayer while others say it's better to return an IList. What is your oppinion on this?
The above code samples in the first question are pointing to the Repository, but what is the bestway to implement the repository in the businesslayer (Initialize in the constructor, use "Using"??)