コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CodeWriter"/> class.
        /// </summary>
        /// <param name="schema">The schema.</param>
        /// <param name="codeWriterSettings">The code writer settings.</param>
        public CodeWriter(DatabaseSchema schema, CodeWriterSettings codeWriterSettings)
        {
            if (schema == null)
            {
                throw new ArgumentNullException("schema");
            }
            if (codeWriterSettings == null)
            {
                throw new ArgumentNullException("codeWriterSettings");
            }

            _schema             = schema;
            _codeWriterSettings = codeWriterSettings;

            var vs2010 = _codeWriterSettings.WriteProjectFile;
            var vs2015 = _codeWriterSettings.WriteProjectFileNet46;

            _projectVersion = vs2015 ? ProjectVersion.Vs2015 : vs2010 ? ProjectVersion.Vs2010 : ProjectVersion.Vs2008;
            //cannot be .net 3.5
            if (IsCodeFirst() && _projectVersion == ProjectVersion.Vs2008)
            {
                _projectVersion = ProjectVersion.Vs2015;
            }

            PrepareSchemaNames.Prepare(schema, codeWriterSettings.Namer);
        }
コード例 #2
0
 public EntityWriter(DatabaseSchema schema, CodeWriterSettings codeWriterSettings)
 {
     this.schema             = schema;
     this.codeWriterSettings = codeWriterSettings;
     PrepareSchemaNames.Prepare(schema, this.codeWriterSettings.Namer);
     dataAnnotationWriter = new DataAnnotationWriter(false, codeWriterSettings);
     mappingNamer         = new MappingNamer();
 }
コード例 #3
0
        /// <summary>
        /// Writes the C# code of the table
        /// </summary>
        /// <returns></returns>
        public string Write()
        {
            var codeTarget = _codeWriterSettings.CodeTarget;

            _dataAnnotationWriter = new DataAnnotationWriter(IsEntityFramework(), _codeWriterSettings);
            var className = _table.NetName;

            if (string.IsNullOrEmpty(className) && _table.DatabaseSchema != null)
            {
                PrepareSchemaNames.Prepare(_table.DatabaseSchema, _codeWriterSettings.Namer);
                className = _table.NetName;
            }
            _dataTypeWriter.CodeTarget = codeTarget;

            _inheritanceTable = _table.FindInheritanceTable();

            WriteNamespaces();
            _codeWriterSettings.CodeInserter.WriteNamespaces(_table, _cb);

            if (!string.IsNullOrEmpty(_codeWriterSettings.Namespace))
            {
                _cb.BeginNest("namespace " + _codeWriterSettings.Namespace);
            }

            if (codeTarget == CodeTarget.PocoRiaServices)
            {
                WriteRiaClass(className);
            }
            else
            {
                var tableOrView     = _table is DatabaseView ? "view" : "table";
                var comment         = "Class representing " + _table.Name + " " + tableOrView;
                var classDefinition = "public class " + className;
                if (_inheritanceTable != null)
                {
                    classDefinition += " : " + _inheritanceTable.NetName;
                }

                _codeWriterSettings.CodeInserter.WriteTableAnnotations(_table, _cb);

                using (_cb.BeginNest(classDefinition, comment))
                {
                    WriteClassMembers(className);
                }
            }

            if (_table.HasCompositeKey && _inheritanceTable == null)
            {
                WriteCompositeKeyClass(className);
            }

            if (!string.IsNullOrEmpty(_codeWriterSettings.Namespace))
            {
                _cb.EndNest();
            }

            return(_cb.ToString());
        }
コード例 #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CodeWriter"/> class.
        /// </summary>
        /// <param name="schema">The schema.</param>
        /// <param name="codeWriterSettings">The code writer settings.</param>
        public CodeWriter(DatabaseSchema schema, CodeWriterSettings codeWriterSettings)
        {
            if (schema == null)
            {
                throw new ArgumentNullException("schema");
            }
            if (codeWriterSettings == null)
            {
                throw new ArgumentNullException("codeWriterSettings");
            }

            _schema             = schema;
            _codeWriterSettings = codeWriterSettings;

            PrepareSchemaNames.Prepare(schema, codeWriterSettings.Namer);
        }
コード例 #5
0
        /// <summary>
        /// Writes the C# code of the table
        /// </summary>
        /// <returns></returns>
        public string Write()
        {
            var codeTarget = _codeWriterSettings.CodeTarget;

            _dataAnnotationWriter = new DataAnnotationWriter(IsEntityFramework(), _codeWriterSettings);
            var className = _table.NetName;

            if (string.IsNullOrEmpty(className) && _table.DatabaseSchema != null)
            {
                PrepareSchemaNames.Prepare(_table.DatabaseSchema);
                className = _table.NetName;
            }
            _dataTypeWriter.CodeTarget = codeTarget;

            WriteNamespaces();

            if (!string.IsNullOrEmpty(_codeWriterSettings.Namespace))
            {
                _cb.BeginNest("namespace " + _codeWriterSettings.Namespace);
            }

            if (codeTarget == CodeTarget.PocoRiaServices)
            {
                WriteRiaClass(className);
            }
            else
            {
                var tableOrView = _table is DatabaseView ? "view" : "table";
                using (_cb.BeginNest("public class " + className, "Class representing " + _table.Name + " " + tableOrView))
                {
                    WriteClassMembers(className);
                }
            }

            if (_table.HasCompositeKey)
            {
                WriteCompositeKeyClass(className);
            }

            if (!string.IsNullOrEmpty(_codeWriterSettings.Namespace))
            {
                _cb.EndNest();
            }

            return(_cb.ToString());
        }
コード例 #6
0
        private string Write()
        {
            if (string.IsNullOrEmpty(table.NetName) && table.DatabaseSchema != null)
            {
                PrepareSchemaNames.Prepare(table.DatabaseSchema, codeWriterSettings.Namer);
            }

            CodeWriterUtils.WriteFileHeader(classBuilder);
            WriteUsings();
            CodeWriterUtils.BeginNestNamespace(classBuilder, codeWriterSettings);
            var tableOrView         = table is DatabaseView ? "view" : "table";
            var comment             = $"Interface providing repository CRUD operations for the {table.Name} {tableOrView}";
            var interfaceDefinition = $"public partial interface {CodeWriterUtils.GetRepositoryInterfaceName(table)}";

            classBuilder.AppendXmlSummary(comment);
            classBuilder.BeginNest(interfaceDefinition);
            WriteInterfaceMembers();
            classBuilder.EndNest(); // interface
            classBuilder.EndNest(); // namespace
            return(classBuilder.ToString());
        }
コード例 #7
0
        public string Write()
        {
            if (string.IsNullOrEmpty(table.NetName) && table.DatabaseSchema != null)
            {
                PrepareSchemaNames.Prepare(table.DatabaseSchema, codeWriterSettings.Namer);
            }

            CodeWriterUtils.WriteFileHeader(classBuilder);
            WriteUsings();
            CodeWriterUtils.BeginNestNamespace(classBuilder, codeWriterSettings);

            classBuilder.AppendXmlSummary($"Class representing the {table.Name} table.");
            classBuilder.AppendLine($"[Table(\"\\\"{table.Name}\\\"\")]");
            using (classBuilder.BeginNest($"public partial class {table.NetName}"))
            {
                WriteAllMembers();
            }

            classBuilder.EndNest();
            return(classBuilder.ToString());
        }