作者:荒野中得生存 | 来源:互联网 | 2023-05-18 07:02
ImusingLinqtoSQLformyDALandhaveheardvariousthingsaboutusingstaticmethodsinaweba
I'm using Linq to SQL for my DAL and have heard various things about using static methods in a web application (regarding threading/concurrency issues). At the moment, I created a test DAL, which seems to be functioning fine. However, are there any problems with the way I've created it, since it's static?
我正在为我的DAL使用Linq to SQL,并且已经听说过在Web应用程序中使用静态方法的各种事情(关于线程/并发问题)。目前,我创建了一个测试DAL,它似乎运行良好。但是,我创建它的方式有什么问题,因为它是静态的吗?
public static class TestDAL
{
public static bool GetUserAddress(string username)
{
testDBDataContext dbCOntext= new testDBDataContext();
//Linq code goes here
}
public static void InsertUserNumber(int userID)
{
testDBDataContext dbCOntext= new testDBDataContext();
//...
dbContext.UserDetails.InsertOnSubmit(nUser);
dbContext.SubmitChanges();
}
//etc... All the methods are created in the same way
}
Is this method fine for a web application, or will there be problems in a production environment?
这种方法适用于Web应用程序,还是生产环境中存在问题?
Thanks.
3 个解决方案