好的,我正在创建一个 Web 应用程序。我正在使用 MVC3。我有每个视图的 ViewModel,我也有支持 viewModel 并在我的 sql 表中执行实际 CRUD 操作的数据模型,而我的 viewModel 会根据需要验证和更改数据。
这是一个问题。我一直在编码的方式是
public class MyClassViewModel
{
public string member1{get;set;}
public int member2{get;set;}
public static GetAllMembers(MyClassViewModel obj, out string strErrMsg)
{
// code goes here, read operation
}
public static UpdateMyClass(MyClassViewModel obj, out string strErrMsg)
{
// code goes here, write operation.
}
}
我的 ViewModel 和 DataModels 都是这样编码的,我在 HttpPost 上的控制器只是做这样的事情..
MyClassViewModel.UpdateMember(obj,out strErrMsg)
由于它在每个帖子上创建的 mvc 都是在强类型视图上创建的,这是我的 ViewModel 的一个新对象,因此非静态成员是不同的,并且不会在会话之间共享。
我正在使用 Linq,因此在我使用的 DataModel 的每个静态方法上
var db = new MyApplicationDataContext()
获取我的 linq 课程并进行研究。这解决了我的打开/关闭阅读器问题。
我的问题是,这种设计的并发性有什么问题吗?我知道如果不是通过接口设计的,我在更改数据层时可能会遇到问题,但我非常怀疑根据我的应用程序是否有必要这样做。