private void WriteColumn(DatabaseColumn column, bool notNetName)
        {
            var propertyName = PropertyName(column);
            var dataType     = _dataTypeWriter.Write(column);

            if (notNetName)
            {
                //in EF, you want a fk Id property
                //must not conflict with entity fk name
                propertyName += "Id";
            }

            _codeWriterSettings.CodeInserter.WriteColumnAnnotations(_table, column, _cb);

            var writeAnnotations = true;

            if (column.IsPrimaryKey &&
                _codeWriterSettings.CodeTarget == CodeTarget.PocoEfCore &&
                _table.PrimaryKey.Columns.Count > 1)
            {
                //EF Core doesn't like [Key] annotations on composite keys
                writeAnnotations = false;
            }
            if (writeAnnotations)
            {
                _dataAnnotationWriter.Write(_cb, column);
            }
            //for code first, ordinary properties are non-virtual.
            var useVirtual = !IsEntityFramework();

            _cb.AppendAutomaticProperty(dataType, propertyName, useVirtual);
        }
Beispiel #2
0
        private void WriteColumn(DatabaseColumn column)
        {
            var propertyName = column.NetName;

            // KL: Ensures that property name doesn't match class name
            if (propertyName == column.Table.NetName)
            {
                propertyName = string.Format("{0}Column", propertyName);
            }
            var dataType = _dataTypeWriter.Write(column);
            var isFk     = column.IsForeignKey && column.ForeignKeyTable != null;

            if (isFk)
            {
                //KL: Returning if this is a foreign key. These should be written in a separate step.
                if (IsNHibernate())
                {
                    return;
                }

                if (IsEntityFramework() && (column.IsPrimaryKey || _codeWriterSettings.UseForeignKeyIdProperties))
                {
                    //if it's a primary key AND foreign key, CF requires a scalar property
                    //optionally allow a shadow Id property to be created (convenient for CF)
                    _cb.AppendAutomaticProperty(dataType, propertyName + "Id", true);
                }
                dataType = column.ForeignKeyTable.NetName;
            }

            _dataAnnotationWriter.Write(_cb, column);
            //for code first, ordinary properties are non-virtual.
            var useVirtual = (!IsEntityFramework() || isFk);

            _cb.AppendAutomaticProperty(dataType, propertyName, useVirtual);
        }
        public void TypeString()
        {
            var typewriter = new DataTypeWriter();

            var column = new DatabaseColumn();
            column.DataType = new DataType("VARCHAR2", "System.String");

            var result = typewriter.Write(column);

            Assert.AreEqual("string", result);
        }
        public void TypeInteger()
        {
            var typewriter = new DataTypeWriter();

            var column = new DatabaseColumn();
            column.DataType = new DataType("NUMBER", "System.Int32");

            var result = typewriter.Write(column);

            Assert.AreEqual("int", result);
        }
Beispiel #5
0
        private void WriteColumn(DatabaseColumn column, bool notNetName)
        {
            var propertyName = column.NetName;

            //in case the netName hasn't been set
            if (string.IsNullOrEmpty(propertyName))
            {
                propertyName = column.Name;
            }
            // KL: Ensures that property name doesn't match class name
            if (propertyName == column.Table.NetName)
            {
                propertyName = string.Format("{0}Column", propertyName);
            }
            var dataType = _dataTypeWriter.Write(column);

            if (column.IsPrimaryKey && column.IsForeignKey)
            {
                //a foreign key will be written, so we need to avoid a collision
                var refTable   = column.ForeignKeyTable;
                var fkDataType = refTable != null ? refTable.NetName : column.ForeignKeyTableName;
                if (fkDataType == propertyName)
                {
                    notNetName = true;
                }
            }

            if (notNetName)
            {
                //in EF, you want a fk Id property
                //must not conflict with entity fk name
                propertyName += "Id";
            }

            _codeWriterSettings.CodeInserter.WriteColumnAnnotations(_table, column, _cb);

            _dataAnnotationWriter.Write(_cb, column);
            //for code first, ordinary properties are non-virtual.
            var useVirtual = !IsEntityFramework();

            _cb.AppendAutomaticProperty(dataType, propertyName, useVirtual);
        }