Esempio n. 1
0
 public TableMapper(SqliteDataReader reader, CreateInstanceDelegate instanceDelegate)
 {
     m_reader = reader;
     m_createInstanceDelegate = instanceDelegate;
     Orm.MappingType(typeof(T));
 }
Esempio n. 2
0
        protected string GetColumnsValue(object obj, out string[] columeNames, out string[] columeValues)
        {
            Type type = obj.GetType();

            FieldInfo[]        fieldInfos = type.GetFields();
            IList <CellMapper> cells      = new List <CellMapper>();

            foreach (FieldInfo fieldInfo in fieldInfos)
            {
                var columeAtt = fieldInfo.AttributeOf <ColumnAttribute>();
                if (null != columeAtt)
                {
                    CellMapper cell = new CellMapper();
                    cell.columeName = columeAtt.columnName;
                    if (string.IsNullOrEmpty(columeAtt.columnName))
                    {
                        cell.columeName = fieldInfo.Name;
                    }
                    cell.dbType  = columeAtt.columnType;
                    cell.type    = fieldInfo.FieldType;
                    cell.notNull = columeAtt.columeNotNull;
                    var primaryKeyAtt = fieldInfo.AttributeOf <PrimaryKeyAttribute>();
                    cell.isPrimaryKey = null != primaryKeyAtt;
                    if (columeAtt.columnType == (DbType.Int32 | DbType.Int64 | DbType.Int16))
                    {
                        var autoIncrease = fieldInfo.AttributeOf <AutoIncrementAttribute>();
                        cell.isAutoIncrease = null != autoIncrease;
                    }
                    cell.value = fieldInfo.GetValue(obj);
                    cells.Add(cell);
                }
            }

            PropertyInfo[] properties = type.GetProperties();
            foreach (PropertyInfo propertyInfo in properties)
            {
                var columeAtt = propertyInfo.AttributeOf <ColumnAttribute>();
                if (null != columeAtt)
                {
                    CellMapper cell = new CellMapper();
                    cell.columeName = columeAtt.columnName;
                    if (string.IsNullOrEmpty(columeAtt.columnName))
                    {
                        cell.columeName = propertyInfo.Name;
                    }
                    cell.dbType  = columeAtt.columnType;
                    cell.type    = propertyInfo.PropertyType;
                    cell.notNull = columeAtt.columeNotNull;
                    var primaryKeyAtt = propertyInfo.AttributeOf <PrimaryKeyAttribute>();
                    cell.isPrimaryKey = null != primaryKeyAtt;
                    if (columeAtt.columnType == (DbType.Int32 | DbType.Int64 | DbType.Int16))
                    {
                        var autoIncrease = propertyInfo.AttributeOf <AutoIncrementAttribute>();
                        cell.isAutoIncrease = null != autoIncrease;
                    }
                    cell.value = propertyInfo.GetValue(obj, null);
                    cells.Add(cell);
                }
            }

            columeNames  = new string[cells.Count];
            columeValues = new string[cells.Count];
            for (int i = 0; i < columeNames.Length; i++)
            {
                columeNames[i]  = cells[i].columeName;
                columeValues[i] = Orm.GetWriteFunc(cells[i].type)(cells[i].value).ToString();
            }

            TableAttribute tableAtt = type.AttributeOf <TableAttribute>();

            if (null != tableAtt)
            {
                return(tableAtt.tableName);
            }
            return(type.Name);
        }
Esempio n. 3
0
 public List <T> Execute2List()
 {
     ExecuteCommand();
     return(Orm.Mapping2List <T>(m_dataReader));
 }