/// <summary> /// Initializes a new instance of the <see cref="InitializeProxyAction"/> class. /// </summary> /// <param name="connection">The connection.</param> /// <param name="transaction">The transaction.</param> /// <param name="metaDataStore">The meta data store.</param> /// <param name="hydrater">The entity hydrater.</param> /// <param name="sessionLevelCache">The session level cache.</param> public InitializeProxyAction( IDbConnection connection, IDbTransaction transaction, MetaDataStore metaDataStore, EntityHydrater hydrater, SessionLevelCache sessionLevelCache) : base(connection, transaction, metaDataStore, hydrater, sessionLevelCache) { }
protected DatabaseAction(SqlConnection connection, SqlTransaction transaction, MetaDataStore metaDataStore, EntityHydrater hydrater, SessionLevelCache sessionLevelCache) { Connection = connection; Transaction = transaction; MetaDataStore = metaDataStore; Hydrater = hydrater; SessionLevelCache = sessionLevelCache; }
public void Delete <TEntity>(TEntity entity) { using (var command = CreateCommand()) { var tableInfo = MetaDataStore.GetTableInfoFor <TEntity>(); command.CommandText = tableInfo.GetDeleteStatement(); object id = tableInfo.PrimaryKey.PropertyInfo.GetValue(entity, null); command.CreateAndAddInputParameter(tableInfo.PrimaryKey.DbType, tableInfo.GetPrimaryKeyParameterName(), id); command.ExecuteNonQuery(); SessionLevelCache.Remove(entity); } }
public TEntity Insert <TEntity>(TEntity entity) { using (var command = CreateCommand()) { var tableInfo = MetaDataStore.GetTableInfoFor <TEntity>(); command.CommandText = tableInfo.GetInsertStatement(); foreach (var parameterInfo in tableInfo.GetParametersForInsert(entity)) { command.CreateAndAddInputParameter(parameterInfo.DbType, parameterInfo.Name, parameterInfo.Value); } object id = Convert.ChangeType(command.ExecuteScalar(), tableInfo.PrimaryKey.DotNetType); tableInfo.PrimaryKey.PropertyInfo.SetValue(entity, id, null); SessionLevelCache.Store(typeof(TEntity), id, entity); return(entity); } }
public TEntity Get <TEntity>(object id) { var cachedEntity = SessionLevelCache.TryToFind(typeof(TEntity), id); if (cachedEntity != null) { return((TEntity)cachedEntity); } using (var command = CreateCommand()) { var tableInfo = MetaDataStore.GetTableInfoFor <TEntity>(); var query = tableInfo.GetSelectStatementForAllFields(); tableInfo.AddWhereByIdClause(query); command.CommandText = query.ToString(); command.CreateAndAddInputParameter(tableInfo.PrimaryKey.DbType, tableInfo.GetPrimaryKeyParameterName(), id); return(Hydrater.HydrateEntity <TEntity>(command)); } }
public InsertAction(SqlConnection connection, SqlTransaction transaction, MetaDataStore metaDataStore, EntityHydrater hydrater, SessionLevelCache sessionLevelCache) : base(connection, transaction, metaDataStore, hydrater, sessionLevelCache) { }