我一直在使用MVC应用程序并创建操作数据的仓库,包括验证、更新、读写。它们都是静态的。以下是一个示例:
public static int Create(user u)
{
using(DataContext db = new DataContext())
{
//do the thing and submit changes...
}
//return the new user id
}
(注意:这只是一个示例,我不需要有关创建用户或返回用户ID等的提示。)
那么我只需调用int id = RepoClassName.Create(userVariable);
使用静态方法是否存在问题?我只是不明白为什么需要实例化对象来完成此操作。