//启动一个事务
using (TransactionScope scope = new TransactionScope())
{
//EF上下文
using (TestDatabaseEntities contect = new TestDatabaseEntities())
{
//string sql = "select VALUE p from TestDatabaseEntities.UserInfo as p";
//var result = contect.CreateQuery<UserInfo>(sql);
//foreach (UserInfo item in result)
//{
// string id = item.Name;
//}
List<string> procs = new List<string>();
procs.Add("EXEC CheckUserPROC3");
//procs.Add("CheckUserPROC2");
//为了动态调用存储过程创建相应的链接对象和命令对象 但是这东西是指向EDM的
//所以如果你的存储过程如果没有添加到你的EDM文件里的话是找不到的,高手解答
//而且这东西是Entity Sql 郁闷啊
System.Data.Common.DbConnection connection = contect.Connection;
System.Data.Common.DbCommand command = connection.CreateCommand();
command.CommandType = CommandType.StoredProcedure;
if (connection.State != ConnectionState.Open)
connection.Open();
string database = connection.Database;
foreach (var item in procs)
{
command.CommandText = item;
command.ExecuteNonQuery();
var result = command.ExecuteScalar();
}
}
}
EF也是可以执行sql语句的 具体你需要Google一下