Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public partial class DataContext : DbContext, IDataContext
- {
- public DataContext()
- : base("name=DataContext")
- {
- }
- public DataContext(DbConnection existingConnection, bool contextOwnsConnection) : base(existingConnection, contextOwnsConnection)
- {
- }
- public string UserID { get; set; }
- public override int SaveChanges()
- {
- SetDbSession();
- return base.SaveChanges();
- }
- private void SetDbSession()
- {
- //Open a connection to the database so the session is set up
- this.Database.Connection.Open();
- //Set the db session
- //ExecuteSqlCommand ot to be used as it will close the connection
- using (var cmd = this.Database.Connection.CreateCommand())
- {
- var parm = cmd.CreateParameter();
- parm.ParameterName = "@userId";
- parm.Value = UserID ;
- cmd.CommandText = "SetDbSession";
- cmd.CommandType = System.Data.CommandType.StoredProcedure;
- cmd.Parameters.Add(parm);
- cmd.ExecuteNonQuery();
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement