示例#1
0
        public static void WritePOCO(bool overread, bool overwrite = true)
        {
            if (_tables == null || overread)
            {
                GetTables();
            }
            string        baseFolder = ProjectContainer.DomainEntity.ToDirectory();
            StringBuilder build      = new StringBuilder();

            foreach (Table tbl in _tables.Where(t => !t.IsMapping).OrderBy(x => x.NameHumanCase))
            {
                foreach (Column col in tbl.Columns.OrderBy(x => x.Ordinal).Where(x => !x.Hidden))
                {
                    build.AppendLine("        " + WritePocoColumn(col));
                }
                ModelContainer.Regist("$Property$", build.ToString(), "实体自身属性");
                build.Clear();
                if (tbl.ReverseNavigationProperty.Count() > 0)
                {
                    foreach (string s in tbl.ReverseNavigationProperty.OrderBy(x => x))
                    {
                        build.AppendLine("        " + s);
                    }
                }
                ModelContainer.Regist("$Navigation$", build.ToString(), "实体导航属性");
                build.Clear();
                if (tbl.HasForeignKey)
                {
                    foreach (Column col in from c in tbl.Columns.OrderBy(x => x.EntityFk) where c.EntityFk != null select c)
                    {
                        build.AppendLine("        " + col.EntityFk);
                    }
                }
                ModelContainer.Regist("$ForeignKey$", build.ToString(), "实体外键属性");
                build.Clear();
                if (tbl.Columns.Where(c => c.Default != string.Empty).Count() > 0 || tbl.ReverseNavigationCtor.Count() > 0)
                {
                    build.AppendLine("        public " + tbl.Name + "()");
                    build.AppendLine("        {");
                    foreach (Column col in tbl.Columns.OrderBy(x => x.Ordinal).Where(c => c.Default != string.Empty))
                    {
                        build.AppendLine("          " + col.PropertyName + "=" + col.Default + ";");
                    }
                    foreach (string s in tbl.ReverseNavigationCtor)
                    {
                        build.AppendLine("          " + s);
                    }
                    build.AppendLine("        }");
                }
                ModelContainer.Regist("$Constructor$", build.ToString(), "实体构造函数");
                build.Clear();
                CodeCreateManager codeManager = new CodeCreateManager(ConstructType.Entity, new TemplateEntity()
                {
                    Entity = tbl.Name, Data2Obj = tbl.NameHumanCase
                });
                codeManager.IsOverWrite = overwrite;
                codeManager.BuildTaget  = ProjectContainer.DomainEntity;
                codeManager.CreateCode();
            }
        }
示例#2
0
        /// <summary>
        /// 创建应用层的代码
        /// </summary>
        /// <param name="overWrite">是否重写</param>
        /// <param name="overReadEntity">是否重新获取实体信息</param>
        public static void Create(bool overWrite, bool overReadEntity = false)
        {
            if (ProjectContainer.Application == null)
            {
                ProjectContainer.Application = SolutionCommon.Dte.AddClassLibrary(SolutionCommon.Application, true);
            }
            if (ProjectContainer.IApplication == null)
            {
                ProjectContainer.IApplication = SolutionCommon.Dte.AddClassLibrary(SolutionCommon.IApplication, true);
            }

            List <TemplateEntity> entitys = DomainEntityLogic.GetEntitys(overReadEntity);

            for (int i = 0; i < entitys.Count; i++)
            {
                // _work.ReportProgress((int)((i + 1) * 100 / entitys.Length), string.Format("添加实体类-{0}-的代码", fileEntity));
                TemplateEntity tmpEntity = entitys[i];

                CodeCreateManager codeManager = new CodeCreateManager(ConstructType.Application, tmpEntity);
                codeManager.IsOverWrite = overWrite;
                codeManager.BuildTaget  = ProjectContainer.Application;
                codeManager.CreateCode();

                codeManager             = new CodeCreateManager(ConstructType.IApplication, tmpEntity);
                codeManager.IsOverWrite = overWrite;
                codeManager.BuildTaget  = ProjectContainer.IApplication;
                codeManager.CreateCode();
            }
        }
示例#3
0
        public static void WriteConfigFies(bool overread, bool overWrite = true)
        {
            if (_tables == null || overread)
            {
                GetTables();
            }

            string baseFolder = ProjectContainer.Infrastructure.ToDirectory();

            foreach (Table tbl in _tables.Where(t => !t.IsMapping).OrderBy(x => x.NameHumanCase))
            {
                ModelContainer.Regist("$Schema$", tbl.Schema, "数据库命名空间");
                ModelContainer.Regist("$PrimaryKey$", tbl.PrimaryKeyNameHumanCase(), "映射主键内容");
                StringBuilder build = new StringBuilder();
                foreach (Column col in tbl.Columns.Where(x => !x.Hidden).OrderBy(x => x.Ordinal))
                {
                    build.AppendLine(col.Config);
                }
                ModelContainer.Regist("$Property$", build.ToString(), "映射自身属性内容");
                build.Clear();
                if (tbl.HasForeignKey)
                {
                    foreach (Column col in from c in tbl.Columns.OrderBy(x => x.Ordinal) where c.ConfigFk != null select c)
                    {
                        build.AppendLine(col.ConfigFk);
                    }
                }
                ModelContainer.Regist("$ForeignKey$", build.ToString(), "映射外键属性内容");
                CodeCreateManager codeManager = new CodeCreateManager(ConstructType.Map, new TemplateEntity()
                {
                    Entity = tbl.Name, Data2Obj = tbl.NameHumanCase
                });
                codeManager.IsOverWrite = overWrite;
                codeManager.BuildTaget  = ProjectContainer.Infrastructure;
                codeManager.CreateCode();
            }
        }