Ejemplo n.º 1
0
        public StandardTableMapping(Type type, TableMappingConfiguration configuration,
                                    string contextName,
                                    CreateFlags createFlags = CreateFlags.None)
        {
            MappedType = type;

            TableName = contextName + ORMUtilities.GetTableName(MappedType);
            string path = string.IsNullOrEmpty(contextName) ? "" : contextName;

            Columns = ORMUtilities.GetColumnsOnType(type, configuration, createFlags, path);

            _autoPk    = DirectColumns.FirstOrDefault(column => column.IsAutoInc && column.IsPK);
            PrimaryKey = DirectColumns.FirstOrDefault(column => column.IsPK);

            if (PrimaryKey != null)
            {
                GetByPrimaryKeySql = string.Format("select * from \"{0}\" where \"{1}\" = ?", TableName, PrimaryKey.Name);
            }
            else
            {
                // People should not be calling Get/Find without a PK
                GetByPrimaryKeySql = string.Format("select * from \"{0}\" limit 1", TableName);
            }

            _insertCommandMap = new ConcurrentStringDictionary();
        }
Ejemplo n.º 2
0
        public static TableMappingColumn[] GetColumnsOnType(Type type, TableMappingConfiguration configuration, CreateFlags createFlags, string path)
        {
            var tableColumns = new List <TableMappingColumn>();
            List <MemberInfo> eligibleMembers = new List <MemberInfo>();

            eligibleMembers.AddRange(configuration.PropertyCollector.Collect(type));
            eligibleMembers.AddRange(configuration.FieldCollector.Collect(type));

            foreach (var info in eligibleMembers)
            {
                tableColumns.AddRange(configuration.TableMappingColumnFactory.CreateColumnsOnMember(info, configuration, createFlags, path));
            }

            return(tableColumns.ToArray());
        }
Ejemplo n.º 3
0
        public static long GetPrimaryKey(object target, TableMappingConfiguration configuration)
        {
            var properties = configuration.PropertyCollector.Collect(target.GetType());
            var fields     = configuration.FieldCollector.Collect(target.GetType());

            List <MemberInfo> infoList = new List <MemberInfo>();

            infoList.AddRange(properties);
            infoList.AddRange(fields);

            MemberInfo primaryKeyInfo = infoList.FirstOrDefault(info => ORMUtilitiesHelperFactory.Create().GetAttribute <PrimaryKeyAttribute>(info) != null);

            if (primaryKeyInfo == null)
            {
                throw new InvalidOperationException("Parent type of list must have a primary key.");
            }

            var result = ORMUtilities.GetValueFromMember(primaryKeyInfo, target);

            return(Convert.ToInt64(result));
        }