예제 #1
0
 public Table(string tableName, Type tableRootType)
 {
     ExceptionUtils.ThrowIfEmptyString(tableName, "tableName");
     ExceptionUtils.ThrowIfNull(tableRootType, "tableRootType");
     m_TableName        = tableName;
     m_TableRootType    = tableRootType;
     m_PrimaryKeyColumn = new GuidPrimaryKeyColumn(this);
 }
예제 #2
0
        public Column AddDataColumn(MemberInfo member, MemberInfo isSpecifiedMember,
                                    ColumnAttribute columnAttribute)
        {
            Column column;

            if (columnAttribute is ForeignKeyAttribute)
            {
                throw new MappingException("Use AddFKTable() instead");
            }
            else
            {
                if (columnAttribute is PrimaryKeyAttribute)
                {
                    if (isSpecifiedMember != null)
                    {
                        throw new MappingException("Attempting to map the column \"{0}\" as the primary key for table \"{1},\" but the column has an isSpecifiedMember: \"{2}\"",
                                                   columnAttribute.ColumnName, this.m_TableName, isSpecifiedMember.Name);
                    }
                    if (columnAttribute is GuidPrimaryKeyAttribute)
                    {
                        column = new GuidPrimaryKeyColumn(this, member, columnAttribute);
                    }
                    else
                    {
                        column = new PrimaryKeyColumn(this, member, columnAttribute);
                    }
                    if (!HasDefaultPrimaryKeyColumn)
                    {
                        // In this case, the table already has a user-defined PrimaryKey column,
                        // so add this next PrimaryKey column as an additional column, this would be
                        // for a table with a compound PrimaryKey (two or more columns as PrimaryKey).
                        CollectionUtils.Add(column as PrimaryKeyColumn, ref m_AdditionalPrimaryKeyColumns);
                        //throw new MappingException("Attempting to map the column \"{0}\" as the primary key for table \"{1},\" but the already has a primary key column mapped to it: \"{2}\"",
                        //                            columnAttribute.ColumnName, this.m_TableName, m_PrimaryKeyColumn.ColumnName);
                    }
                    else
                    {
                        m_PrimaryKeyColumn = column as PrimaryKeyColumn;
                    }
                }
                else
                {
                    column = new Column(this, member, isSpecifiedMember, columnAttribute);
                    CollectionUtils.Add(column, ref m_DataColumns);
                }
                m_AllColumns = m_DirectColumns = null;
            }
            return(column);
        }