EntityFramework4 调用存储过程

测试存储过程:

create proc proc_test
@a int,
@b int,
@sum int out,
@mul int out
as
set @sum=@a+@b
set @mul=@a*@b
go

在EntityFramework 中添加存储过程:

EntityFramework4 调用存储过程_第1张图片

EntityFramework4 调用存储过程_第2张图片

            var cmd = this.ObjectContext.Connection.CreateCommand();
            cmd.CommandText = "HahaEntities.proc_test";
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new EntityParameter
            {
                ParameterName = "a",
                Value =10
            });
            cmd.Parameters.Add(new EntityParameter
            {
                ParameterName = "b",
                Value = 20
            });
            cmd.Parameters.Add(new EntityParameter
            {
                ParameterName = "sum",
                DbType = System.Data.DbType.Int32,
                Direction = ParameterDirection.Output
            });
            cmd.Parameters.Add(new EntityParameter
            {
                ParameterName = "mul",
                DbType = System.Data.DbType.Int32,
                Direction = ParameterDirection.Output
            });
            cmd.Connection.Open();
            cmd.ExecuteNonQuery();
            cmd.Connection.Close();
            int sum = Convert.ToInt32(cmd.Parameters["sum"].Value);
            int mul = Convert.ToInt32(cmd.Parameters["mul"].Value);


结果:

EntityFramework4 调用存储过程_第3张图片

 

你可能感兴趣的:(entityframework,entityframework)