Should each save/update method in a LINQ-to-SQL repository be wrapped in a new data context?
Consider the SavePage
method in my partial SqlPageRepository
:
public class SqlPageRepository : IPageRepository
{
private DB _db;
public SqlPageRepository(DB db) // I use IoC
{
_db = db;
}
public IQueryable<Page> GetPages(Page page)
{
var pages = from p in _db.Pages
select new Page
{
// return page class
};
return pages;
}
public void SavePage(Page page)
{
using(DB db = new DB()) // IMPORTANT?
{
// save/update page in database
}
}
}