Please visit DEMANDDRAFT.SHOP for quality of products...

Ad

Search This Blog

Friday, June 5, 2015

How to get the data from Data base using Stored procedure using Entity Framework in Code First Approach



public List<DTO_HSData_SData> GetSInformationForProcure(int sId)
        {
            var sApproval = new List<DTO_HSData_SData>();
            using (var db = new SContext())
            {
                using (db.Database.Connection)
                {
                    var context = ((IObjectContextAdapter)db).ObjectContext;
                    db.Database.Connection.Open();
                    DbCommand cmd = db.Database.Connection.CreateCommand();
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;
                    cmd.CommandText = "USP_GetHealthAndSafetyStatus_ForProcurement_BySupplierID";
                    cmd.Parameters.Add(new SqlParameter("@SId", sId));
                    supplierApproval = context.Translate<DTO_HSData_SData>(cmd.ExecuteReader()).ToList();
                    db.Database.Connection.Close();
                }
            }
            return sApproval ;
        }

No comments:

Post a Comment