I've hit on the idea of creating static methods on the partial Linq queries such as
public partial class User
{
public static User FindByGuid(string guid, ApplicationDataContext context)
{
return context.Users.Where(x => x.GUID == guid).Single();
}
}
So, for example, I can easily find a user by doing:
using (var context = new ApplicationDataContext())
{
var user = DataAccess.User.FindByGuid(UsersDropDown.SelectedValue, context);
}
Is this a recognised design pattern? What are the advantages/disadvantages of doing this vs the repository model?
-
While I don't see a recognized pattern in what your doing here I do see that you are using Dependency Injection by passing the applicationdatacontext into the method as a dependency. The problem here is that you are still tightly coupled to your datacontext regardless of where the dependency is initiated which makes it more difficult to unit test.
From David Yancey
0 comments:
Post a Comment