In the past few months, I have learned a lot about Linq-To-Entities and the three-tier architecture with DAO / DAL / Repository. Now I have something that bothers me. I have three questions that you will see below.
There are many ways to make a repository work, but how is this a βwayβ to make a repository work as a way of performance.
1) Initialize datacontext in 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 "Use"
public class Repository : IRepository { public IList<Entity> GetEntities() { using (Datacontext context = new Datacontext()) { return (from e in context.Entity select e).ToList(); } } }
3) In a different way (please comment)
I will put your suggestion here for others to comment
It also seems that some people say that the repository should return the IQueryable to the business layer, while others say that it is better to return the IList. What is your attitude to this?
The above code examples in the first question point to the repository, but what is the best way to implement the repository in a business word (Initialize in the constructor, use "Use" ??)
source share