I had the same problem where i needed to do a mass insert so i came up
with the attached class that allows you to run arbitrary sql commands on
database. Then i created an Insert method in class, something like this:

public class Expense :  ActiveRecordBase<Expense> {
    ...
    public void Insert() {
        ArbitrarySqlQuery q = new ArbitrarySqlQuery(
@"insert into Expense (Amount, Batch, Owner) values (@Amount, @Batch,
@Owner)", typeof (Expense));
    
        q.AddParameter("@Amount", DbType.Double, Amount);
        q.AddParameter("@Batch", DbType.String, Batch);
        q.AddParameter("@Owner", DbType.String, Owner);
        ExecuteQuery(q);
    }
}

Hope this helps...

On Thu, 2006-09-14 at 10:38 -0400, Seth Soffer wrote: 
> I totally agree, but this developer is being stubborn.  He's
> complaining, "I wanna deal with objects".  And he's bitching up a
> storm about ActiveRecord.  I keep telling him to be flexible, and that
> ADO.NET and MS Enterprise library is ideal for importing data and that
> XML is data.  I just thought that someone here could give me some
> intellectual firepower to put this guy in his place.
> 
> I think I'm going to have to take the task from him, and do it myself. :/
> 
> On 9/14/06, Carlos Ble <[EMAIL PROTECTED]> wrote:
> > The import process could be performed with ADO.NET, just INSERT INTO and
> > so on. Once the data have been inserted, your developer can use
> > ActiveRecord models.
> > Greetings
> >
> >
> > El jue, 14-09-2006 a las 09:44 -0400, Seth Soffer escribió:
> > > I'm managing a project where a developer is importing data from a huge
> > > XML file (300 mb) into a SQL 2005 db.  However, the imported records
> > > are a subset of the xml.  We have active record object which he is
> > > using to load the data into and persist into the database.  The import
> > > is taking a long time.  Its wrapped up in one big transaction.
> > >
> > > I feel that Active Record may not be the way to go with this task, but
> > > the developer is resistant to trying another methodology.  Any advice?
> > >
> > > -------------------------------------------------------------------------
> > > Using Tomcat but need to do more? Need to support web services, security?
> > > Get stuff done quickly with pre-integrated technology to make your job 
> > > easier
> > > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> > > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> > > _______________________________________________
> > > CastleProject-users mailing list
> > > CastleProject-users@lists.sourceforge.net
> > > https://lists.sourceforge.net/lists/listinfo/castleproject-users
> > --
> > Carlos Ble
> > Shidix Technologies
> > www.shidix.com/carlosble
> >
> >
> >
> > -------------------------------------------------------------------------
> > Using Tomcat but need to do more? Need to support web services, security?
> > Get stuff done quickly with pre-integrated technology to make your job 
> > easier
> > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> > _______________________________________________
> > CastleProject-users mailing list
> > CastleProject-users@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/castleproject-users
> >
> 
> -------------------------------------------------------------------------
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> CastleProject-users mailing list
> CastleProject-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/castleproject-users
namespace Castle.ActiveRecord {
    internal class ArbitrarySqlParameter {
        private readonly string parameterName;
        private readonly DbType type;
        private readonly object value;

        public ArbitrarySqlParameter(string parameterName, DbType type, object value) {
            this.parameterName = parameterName;
            this.type = type;
            this.value = value;
        }

        public string ParameterName {
            get { return parameterName; }
        }

        public DbType Type {
            get { return type; }
        }

        public object Value {
            get { return value; }
        }
    }

    internal class ArbitrarySqlQuery : ActiveRecordBaseQuery {
        private string query;
        private List<ArbitrarySqlParameter> parameters = new List<ArbitrarySqlParameter>();

        public ArbitrarySqlQuery(string sql, Type T) : base(T) {
            query = sql;
        }

        public void AddParameter(ArbitrarySqlParameter parameter) {
            parameters.Add(parameter);
        }

        public void AddParameter(string parameterName, DbType dbType, object value) {
            parameters.Add(new ArbitrarySqlParameter(parameterName, dbType, value));
        }

        protected override IQuery CreateQuery(ISession session) {
            return null;
        }

        protected override object InternalExecute(ISession session) {
            using (IDbCommand cmd = session.Connection.CreateCommand()) {
                if (session.Transaction != null) {
                    session.Transaction.Enlist(cmd);
                }
                cmd.CommandText = query;
                foreach (ArbitrarySqlParameter p in parameters) {
                    IDataParameter par = cmd.CreateParameter();
                    par.ParameterName = p.ParameterName;
                    par.DbType = p.Type;
                    par.Value = p.Value;
                    cmd.Parameters.Add(par);
                }
                cmd.ExecuteNonQuery();
            }
            return null;
        }
    }
}
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
CastleProject-users mailing list
CastleProject-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/castleproject-users

Reply via email to