Ejemplo n.º 1
0
        public ResultSet(SqlCommand command, System.Data.DataSet dataSet, IModelValueBinder modelValueBinder)
        {
            this.CommandText  = command.CommandText;
            _dataSet          = dataSet;
            _modelValueBinder = modelValueBinder;
            for (int i = 0; i < command.Parameters.Count; i++)
            {
                var prm = command.Parameters[i];
                _parameters.Add(prm.ParameterName, prm.Value);
            }

            ReturnValue = Convert.ToInt32(GetParameterValue(ReturnValueParameterName) ?? 0);
        }
Ejemplo n.º 2
0
        private TModel[] ToModel <TModel>(System.Data.DataTable table)
            where TModel : class, new()
        {
            var models = new List <TModel>();

            IModelValueBinder binder = _modelValueBinder ?? new DefaultModelValueBinder(typeof(TModel));

            if (typeof(TModel) == typeof(System.Dynamic.ExpandoObject))
            {
                foreach (System.Data.DataRow row in table.Rows)
                {
                    var model = new System.Dynamic.ExpandoObject();

                    foreach (System.Data.DataColumn col in table.Columns)
                    {
                        var val = row[col];
                        if (val != null && val.GetType() == typeof(DBNull))
                        {
                            val = null;
                        }

                        var dictionary = (IDictionary <string, object>)model;
                        dictionary.Add(col.ColumnName, val);
                    }

                    models.Add(model as TModel);
                }
            }
            else
            {
                foreach (System.Data.DataRow row in table.Rows)
                {
                    var model = new TModel();

                    foreach (System.Data.DataColumn col in table.Columns)
                    {
                        var val = row[col];
                        if (val != null && val.GetType() == typeof(DBNull))
                        {
                            val = null;
                        }

                        binder.SetValue(model, col.ColumnName, val);
                    }

                    models.Add(model);
                }
            }

            return(models.ToArray());
        }
Ejemplo n.º 3
0
 public PBL(string connectionString, IModelValueBinder modelValueBinder)
     : base(connectionString, modelValueBinder)
 {
 }
Ejemplo n.º 4
0
 public Database(string connectionString, IModelValueBinder modelValueBinder)
 {
     _connectionString = connectionString;
     _modelValueBinder = modelValueBinder;
 }