コード例 #1
0
        public string Write()
        {
            WriteUsings();

            MappingClassName = _mappingNamer.NameMappingClass(_table.NetName);

            _inheritanceTable = _table.FindInheritanceTable();

            using (_cb.BeginNest("namespace " + _codeWriterSettings.Namespace + ".Mapping"))
            {
                using (_cb.BeginNest("public class " + MappingClassName + " : EntityTypeConfiguration<" + _table.NetName + ">", "Class mapping to " + _table.Name + " table"))
                {
                    using (_cb.BeginNest("public " + MappingClassName + "()", "Constructor"))
                    {
                        MapTableName();

                        AddPrimaryKey();

                        _cb.AppendLine("// Properties");
                        WriteColumns();

                        WriteForeignKeys();

                        WriteNavigationProperties();
                    }
                }
            }

            return(_cb.ToString());
        }
コード例 #2
0
        public string Write()
        {
            _cb.AppendLine("using FluentNHibernate.Mapping;");

            MappingClassName = _mappingNamer.NameMappingClass(_table.NetName);

            using (_cb.BeginNest("namespace " + _codeWriterSettings.Namespace + ".Mapping"))
            {
                using (_cb.BeginNest("public class " + MappingClassName + " : ClassMap<" + _table.NetName + ">", "Class mapping to " + _table.Name + " table"))
                {
                    using (_cb.BeginNest("public " + MappingClassName + "()", "Constructor"))
                    {
                        if (_table.Name != _table.NetName)
                        {
                            var name = _table.Name;
                            if (name.Contains(" "))
                            {
                                name = "`" + name + "`";
                            }
                            _cb.AppendFormat("Table(\"{0}\");", name);
                        }

                        AddPrimaryKey();
                        WriteColumns();

                        foreach (var foreignKeyChild in _table.ForeignKeyChildren)
                        {
                            WriteForeignKeyCollection(foreignKeyChild);
                        }
                    }
                }
            }

            return(_cb.ToString());
        }
コード例 #3
0
        public string Write()
        {
            _cb.AppendLine("using FluentNHibernate.Mapping;");

            MappingClassName = _mappingNamer.NameMappingClass(_table.NetName);

            var hasTablePerTypeInheritance =
                (_table.ForeignKeyChildren.Count(fk => _table.IsSharedPrimaryKey(fk)) > 1);

            _inheritanceTable = _table.FindInheritanceTable();
            var classMap = (_inheritanceTable != null) ? "SubclassMap" : "ClassMap";

            using (_cb.BeginNest("namespace " + _codeWriterSettings.Namespace + ".Mapping"))
            {
                using (_cb.BeginNest("public class " + MappingClassName + " : " + classMap + "<" + _table.NetName + ">", "Class mapping to " + _table.Name + " table"))
                {
                    using (_cb.BeginNest("public " + MappingClassName + "()", "Constructor"))
                    {
                        if (_table.Name != _table.NetName)
                        {
                            var name = _table.Name;
                            if (name.Contains(" "))
                            {
                                name = "`" + name + "`";
                            }
                            _cb.AppendFormat("Table(\"{0}\");", name);
                        }

                        AddPrimaryKey();
                        WriteColumns();

                        foreach (var foreignKeyChild in _table.ForeignKeyChildren)
                        {
                            if (hasTablePerTypeInheritance && _table.IsSharedPrimaryKey(foreignKeyChild))
                            {
                                continue;
                            }

                            WriteForeignKeyCollection(foreignKeyChild);
                        }
                    }
                }
            }

            return(_cb.ToString());
        }
コード例 #4
0
        public string Write()
        {
            WriteUsings();

            MappingClassName = _mappingNamer.NameMappingClass(_table.NetName);

            _inheritanceTable = _table.FindInheritanceTable();

            using (_cb.BeginNest("namespace " + _codeWriterSettings.Namespace + ".Mapping"))
            {
                var cdef = (_codeWriterSettings.CodeTarget == CodeTarget.PocoEfCore)
                    ? "public static class " + MappingClassName
                    : "public class " + MappingClassName + " : EntityTypeConfiguration<" + _table.NetName + ">";
                using (_cb.BeginNest(cdef, "Class mapping to " + _table.Name + " table"))
                {
                    var mapMethod = _codeWriterSettings.CodeTarget == CodeTarget.PocoEfCore
                        ? "public static void Map(EntityTypeBuilder<" + _table.NetName + "> b)"
                        : "public " + MappingClassName + "()";
                    using (_cb.BeginNest(mapMethod, "Mapping"))
                    {
                        MapTableName();

                        AddPrimaryKey();

                        _cb.AppendLine("// Properties");
                        WriteColumns();

                        WriteForeignKeys();

                        WriteNavigationProperties();
                    }
                }
            }

            return(_cb.ToString());
        }
コード例 #5
0
        public string Write()
        {
            _cb.AppendLine("using System.ComponentModel.DataAnnotations;");
            if (_table.PrimaryKeyColumn != null && !_table.PrimaryKeyColumn.IsIdentity)
            {
                //in EF v5 DatabaseGeneratedOption is in DataAnnotations.Schema
                _cb.AppendLine("using System.ComponentModel.DataAnnotations.Schema;");
            }
            _cb.AppendLine("using System.Data.Entity.ModelConfiguration;");

            MappingClassName = _mappingNamer.NameMappingClass(_table.NetName);

            using (_cb.BeginNest("namespace " + _codeWriterSettings.Namespace + ".Mapping"))
            {
                using (_cb.BeginNest("public class " + MappingClassName + " : EntityTypeConfiguration<" + _table.NetName + ">", "Class mapping to " + _table.Name + " table"))
                {
                    using (_cb.BeginNest("public " + MappingClassName + "()", "Constructor"))
                    {
                        MapTableName();

                        AddPrimaryKey();

                        _cb.AppendLine("// Properties");
                        WriteColumns();

                        _cb.AppendLine("// Navigation properties");
                        foreach (var foreignKeyChild in _table.ForeignKeyChildren)
                        {
                            WriteForeignKeyCollection(foreignKeyChild);
                        }
                    }
                }
            }

            return(_cb.ToString());
        }