Пример #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);
        }
Пример #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());
        }
Пример #3
0
 public PBL(string connectionString, IModelValueBinder modelValueBinder)
     : base(connectionString, modelValueBinder)
 {
 }
Пример #4
0
 public Database(string connectionString, IModelValueBinder modelValueBinder)
 {
     _connectionString = connectionString;
     _modelValueBinder = modelValueBinder;
 }