示例#1
0
        public PocoData(Type t, IMapper mapper, Cache <string, Type> aliasToTypeCache) : this()
        {
            aliasToType = aliasToTypeCache;
            type        = t;
            Mapper      = mapper;
            TableInfo   = TableInfo.FromPoco(t);

            // Call column mapper
            if (Mapper != null)
            {
                Mapper.GetTableInfo(t, TableInfo);
            }

            var alias = CreateAlias(type.Name, type);

            TableInfo.AutoAlias = alias;
            var index = 0;

            // Work out bound properties
            Columns = new Dictionary <string, PocoColumn>(StringComparer.OrdinalIgnoreCase);
            foreach (var mi in ReflectionUtils.GetFieldsAndPropertiesForClasses(t))
            {
                ColumnInfo ci = ColumnInfo.FromMemberInfo(mi);
                if (ci.IgnoreColumn)
                {
                    continue;
                }

                var pc = new PocoColumn();
                pc.TableInfo         = TableInfo;
                pc.MemberInfo        = mi;
                pc.ColumnName        = ci.ColumnName;
                pc.ResultColumn      = ci.ResultColumn;
                pc.ForceToUtc        = ci.ForceToUtc;
                pc.ComputedColumn    = ci.ComputedColumn;
                pc.ColumnType        = ci.ColumnType;
                pc.ColumnAlias       = ci.ColumnAlias;
                pc.VersionColumn     = ci.VersionColumn;
                pc.VersionColumnType = ci.VersionColumnType;

                if (Mapper != null && !Mapper.MapMemberToColumn(mi, ref pc.ColumnName, ref pc.ResultColumn))
                {
                    continue;
                }

                pc.AutoAlias = alias + "_" + index++;

                // Store it
                if (!Columns.ContainsKey(pc.ColumnName))
                {
                    Columns.Add(pc.ColumnName, pc);
                }
            }

            // Build column list for automatic select
            QueryColumns = Columns.Where(c => !c.Value.ResultColumn).ToArray();
        }
示例#2
0
 protected virtual ColumnInfo GetColumnInfo(MemberInfo mi, Type type)
 {
     return(ColumnInfo.FromMemberInfo(mi));
 }