/// <summary> /// Underline it calls Command.Execute and return the number of row effected. No "returning"(in Oracle) or "output"(in SqlServer) parameter involves. /// </summary> /// <param name="obj"></param> /// <param name="conn"></param> /// <param name="trans"></param> /// <returns></returns> public virtual int Execute(ref T obj, DBConnectionWrapper conn, DBTransactionWrapper trans = null) { var sql = CreateSql(obj); int ret = conn.Execute(sql, false, trans); return(ret); }
public virtual int Delete(T obj, DBConnectionWrapper conn, DBTransactionWrapper trans = null) { if (DeleteCommand == null) { throw new NotSupportedException("Delete is not support for this [" + typeof(T).FullName + "], make sure you have primary key defined in Entity Metadata for this type."); } return(DeleteCommand.Execute(ref obj, conn, trans)); }
public override int Execute(ref T obj, DBConnectionWrapper conn, DBTransactionWrapper trans = null) { var sql = CreateSql(obj); var ret = conn.Query <T>(sql, trans).FirstOrDefault(); if (ret != null) { obj = ret; return(1); } return(0); }
public virtual T Load(T obj, DBConnectionWrapper conn, DBTransactionWrapper trans = null) { if (LoadCommand == null) { throw new NotSupportedException("Load is not support for this [" + typeof(T).FullName + "], make sure you have primary key defined in Entity Metadata for this type."); } int cnt = LoadCommand.Execute(ref obj, conn, trans); if (cnt == 0) { return(default(T)); } return(obj); }
public static T GetSingleValue <T>(this DBConnectionWrapper conn, Sql sql, DBTransactionWrapper trans = null) { IDbCommand command = conn.CreateCommand(sql, trans); try { object val = command.ExecuteScalar(); return(ParseFromDBValue <T>(val)); } catch (DbException ex) { //throw; throw new SqlCmdException("Error occurred when running SQL!", sql, ex); } }
public virtual int Update(ref T obj, DBConnectionWrapper conn, DBTransactionWrapper trans = null, params Expression <Func <T, object> >[] targetProperties) { if (UpdateCommand == null) { throw new NotSupportedException("Update is not support for this [" + typeof(T).FullName + "], make sure you have primary key defined in Entity Metadata for this type."); } IDBTableAdapterCommand <T> cmd = UpdateCommand; if (targetProperties.Length > 0) { cmd = CreateUpdateCommand(targetProperties); } return(cmd.Execute(ref obj, conn, trans)); }
public static List <T> Query <T>(this DBConnectionWrapper conn, Sql sql, DBTransactionWrapper trans = null) where T : new() { IDbCommand command = conn.CreateCommand(sql, trans); try { using (IDataReader reader = command.ExecuteReader()) { return(reader.ToList <T>()); } } catch (DbException ex) { //throw; throw new SqlCmdException("Error occurred when running SQL!", sql, ex); } }
public static T Load <T>(this DBTransactionWrapper trans, T obj) where T : new() { return(trans.Connection.Load <T>(obj, trans)); }
public DBTableAdapterBase(IResolverProvider resolverProvider, ICommandBuilder <T> commandBuilder, DBConnectionWrapper currentConnection, DBTransactionWrapper currentTrans) : base(resolverProvider, currentConnection, currentTrans) { CommandBuilder = commandBuilder; InsertCommand = commandBuilder.CreateInsertCommand(this); UpdateCommand = commandBuilder.CreateUpdateCommand(this); DeleteCommand = commandBuilder.CreateDeleteCommand(this); LoadCommand = commandBuilder.CreateLoadCommand(this); }
public static int Delete <T>(this DBTransactionWrapper trans, T obj) where T : new() { return(trans.Connection.Delete <T>(obj, trans)); }
public static List <T> GetFirstColumn <T>(this DBTransactionWrapper trans, Sql sql) { return(trans.Connection.GetFirstColumn <T>(sql, trans)); }
public static int Update <T>(this DBTransactionWrapper trans, ref T obj, params Expression <Func <T, object> >[] targetProperties) where T : new() { return(trans.Connection.Update <T>(ref obj, trans, targetProperties)); }
public override IDBTableAdapter <T> GetDBTableAdapter <T>(DBConnectionWrapper currentConnection, DBTransactionWrapper currentTrans) { return(DBTableAdapter <T> .Get(this, _CommandBuilderFactory, currentConnection, currentTrans)); }
public abstract IDBTableAdapter <T> GetDBTableAdapter <T>(DBConnectionWrapper currentConnection, DBTransactionWrapper currentTrans) where T : new();
public static int Insert <T>(this DBConnectionWrapper conn, ref T obj, DBTransactionWrapper trans = null) where T : new() { var ta = conn.ResolverProvider.GetDBTableAdapter <T>(conn, trans); return(ta.Insert(ref obj, conn, trans)); }
public static T Load <T>(this DBConnectionWrapper conn, T obj, DBTransactionWrapper trans = null) where T : new() { var ta = conn.ResolverProvider.GetDBTableAdapter <T>(conn, trans); return(ta.Load(obj, conn, trans)); }
public static IDbCommand CreateCommand(this DBConnectionWrapper conn, Sql sql, DBTransactionWrapper trans = null) { return(conn.ResolverProvider.DBClassResolver.CreateCommand(sql, conn, trans)); }
public static List <T> Query <T>(this DBTransactionWrapper trans, Sql sql) where T : new() { return(trans.Connection.Query <T>(sql, trans)); }
public static int Execute(this DBTransactionWrapper trans, Sql sql, bool storeProcedure = false) { return(trans.Connection.Execute(sql, storeProcedure, trans)); }
public static DBTableMapping <T> Get(IResolverProvider resolverProvider, DBConnectionWrapper currentConnection, DBTransactionWrapper currentTrans) { var ret = _Cache[resolverProvider.Idx]; if (ret == null) { return(_Cache[resolverProvider.Idx] = new DBTableMapping <T>(resolverProvider, currentConnection, currentTrans)); } return(ret); }
public virtual int Insert(ref T obj, DBConnectionWrapper conn, DBTransactionWrapper trans = null) { return(InsertCommand.Execute(ref obj, conn, trans)); }
public static IDBTableAdapter <T> Get(IResolverProvider resolverProvider, CommandBuilderFactoryBase commandBuilderFactory, DBConnectionWrapper currentConnection, DBTransactionWrapper currentTrans) { var ret = _Cache[resolverProvider.Idx]; if (ret == null) { var commandBuilder = commandBuilderFactory.CreateCommandBuilder <T>(resolverProvider.SqlResolver); return(_Cache[resolverProvider.Idx] = new DBTableAdapter <T>(resolverProvider, commandBuilder, currentConnection, currentTrans)); } return(ret); }
public static int Update <T>(this DBConnectionWrapper conn, ref T obj, DBTransactionWrapper trans = null, params Expression <Func <T, object> >[] targetProperties) where T : new() { var ta = conn.ResolverProvider.GetDBTableAdapter <T>(conn, trans); return(ta.Update(ref obj, conn, trans, targetProperties)); }
public static int Insert <T>(this DBTransactionWrapper trans, ref T obj) where T : new() { return(trans.Connection.Insert <T>(ref obj, trans)); }
public DBTableAdapterContext(IResolverProvider resolverProvider, DBConnectionWrapper currentConnection, DBTransactionWrapper currentTrans) : this(DBTableMapping <T> .Get(resolverProvider, currentConnection, currentTrans)) { ResolverProvider = resolverProvider; }
public static List <T> GetFirstColumn <T>(this DBConnectionWrapper conn, Sql sql, DBTransactionWrapper trans = null) { IDbCommand command = conn.CreateCommand(sql, trans); var mapping = DBObjectMapping <SingleColumn <T> > .Get().ColumnMappingList.Single(); List <T> ret = new List <T>(); try { using (IDataReader reader = command.ExecuteReader()) { SingleColumn <T> obj = new SingleColumn <T>(); Action <SingleColumn <T>, IDataRecord, int> setter = null; if (reader.Read()) { setter = mapping.GetPropSetterForRecord(reader.GetFieldType(0)); reader.SetProperty(obj, mapping, setter, 0); ret.Add(obj.Val); } while (reader.Read()) { reader.SetProperty(obj, mapping, setter, 0); ret.Add(obj.Val); } } } catch (DbException ex) { //throw; throw new SqlCmdException("Error occurred when running SQL!", sql, ex); } return(ret); }
private DBTableMapping(IResolverProvider resolverProvider, DBConnectionWrapper currentConnection, DBTransactionWrapper currentTrans) { var mapping = DBObjectMapping <T> .Get(); Sql sql = resolverProvider.SqlResolver.ColumnMetaDataFromTable(TableName, Schema); List <SchemaMetadata> metadatas = currentConnection.Query <SchemaMetadata>(sql, currentTrans); ColumnMappingList = mapping.ColumnMappingList .Select(i => new DBColumnMappingInfo <T>(i, metadatas.Single(j => string.Compare(j.COLUMN_NAME, i.ColumnName, true) == 0))); }
public static int Execute(this DBConnectionWrapper conn, Sql sql, bool storeProcedure = false, DBTransactionWrapper trans = null) { IDbCommand command = conn.CreateCommand(sql, trans); if (storeProcedure) { command.CommandType = CommandType.StoredProcedure; } int ret = 0; try { ret = command.ExecuteNonQuery(); for (int i = 0; i < sql.Parameters.Count; i++) { var p = sql.Parameters[i]; if (p.Direction == ParameterDirection.InputOutput || p.Direction == ParameterDirection.Output || p.Direction == ParameterDirection.ReturnValue) { var val = ((DbParameter)command.Parameters[p.Name]).Value; p.Output = (val == DBNull.Value) ? null : val; } } } catch (DbException ex) { //throw; throw new SqlCmdException("Error occurred when running SQL!", sql, ex); } return(ret); }
private DBTableAdapter(IResolverProvider resolverProvider, ICommandBuilder <T> commandBuilder, DBConnectionWrapper currentConnection, DBTransactionWrapper currentTrans) : base(resolverProvider, commandBuilder, currentConnection, currentTrans) { }
public static T GetSingleValue <T>(this DBTransactionWrapper trans, Sql sql) { return(trans.Connection.GetSingleValue <T>(sql, trans)); }