Stored procedures in entity framework

后端 未结 3 1652
没有蜡笔的小新
没有蜡笔的小新 2021-02-09 17:31

I am trying to use a stored procedure in the entity framework that returns nothing. The stored procedure is purely for logging.

I added a function (right click -> add -

3条回答
  •  半阙折子戏
    2021-02-09 18:16

    This is one way of executing a stored procedure from enitity framework:

                using (SEntities se = new SEntities())
                {
                    EntityConnection entityConnection = (EntityConnection)se.Connection;
                    DbConnection storeConnection = entityConnection.StoreConnection;
    
                    storeConnection.Open();
    
                    DbCommand command = storeConnection.CreateCommand();
                    command.CommandText = "NameOfStoredProcedure";
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.Add(new SqlParameter("param1", value_of_param1));
                    command.Parameters.Add(new SqlParameter("param2", value_of_param2));
    
                    SqlParameter param3 = new SqlParameter();
                    pA.SqlDbType = SqlDbType.Bit;
                    pA.ParameterName = "@param3";
                    pA.Direction = ParameterDirection.Output;
                    command.Parameters.Add(param3);
    
                    command.ExecuteNonQuery();
    
                    returnValue = Convert.ToBoolean(param3.Value);
                }
    

提交回复
热议问题