Пример #1
0
        public List <T> LoadData <T>(DataTable tab, FieldMappings maps)
        {
            var result = new List <T>();

            if (tab != null)
            {
                maps.FillProperty(tab);

                foreach (DataRow row in tab.Rows)
                {
                    T newObject = (T)Activator.CreateInstance(maps.EntityType);
                    foreach (var item in maps.Properties)
                    {
                        object objValue = null;
                        if (item.Value.Index >= 0 && item.Value.Index < tab.Columns.Count)
                        {
                            objValue = row[item.Value.Index];
                        }
                        else if (!string.IsNullOrEmpty(item.Value.FieldName))
                        {
                            objValue = row[item.Value.FieldName];
                        }

                        SetPropertyValue(newObject, item.Value.PropertyInfo, objValue);
                    }
                    result.Add(newObject);
                }
            }
            return(result);
        }
Пример #2
0
        public T GetEntity <T>(string sql, FieldMappings maps, params SqlParameter[] parameters)
        {
            T        result   = default(T);
            List <T> entities = LoadData <T>(sql, maps, parameters);

            if (entities.Count > 0)
            {
                result = entities[0];
            }
            return(result);
        }
Пример #3
0
 public List <T> LoadData <T>(string sql, FieldMappings maps, params SqlParameter[] parameters)
 {
     return(LoadData <T>(LoadTable(sql), maps));
 }