【发布时间】:2011-04-20 19:16:39
【问题描述】:
可以在网络上使用这样的东西吗: (我的应用程序在 asp.net mvc 上)
public static class DbUtil
{
public static int Insert(object o, string cs)
{
using (var conn = new SqlConnection(cs))
using (var cmd = conn.CreateCommand())
{
...
conn.Open();
return Convert.ToInt32(cmd.ExecuteScalar());
}
}
}
用法:
public class Repository<T> : IRepository<T>
{
public virtual int Insert(T o)
{
return DbUtil.Insert(o, Cs);
}
}
在服务或控制器中注入构造函数之后
public MyController(
IRepository<Organization> organizationRepository)
{
this.organizationRepository = organizationRepository;
}
【问题讨论】:
-
这完全取决于你如何调用这个方法。你能给我们举例说明它的用法吗?否则不可能说任何有用的东西。
-
@Steven 我已经编辑了我的问题
标签: asp.net asp.net-mvc ado.net data-access-layer