Example #1
0
        /// <summary>为Xml模型文件生成实体类</summary>
        /// <param name="tables">模型文件</param>
        /// <param name="option">生成可选项</param>
        /// <param name="chineseFileName">是否中文名称</param>
        public static Int32 BuildTables(IList <IDataTable> tables, BuilderOption option, Boolean chineseFileName = true)
        {
            if (tables == null || tables.Count == 0)
            {
                return(0);
            }

            if (option == null)
            {
                option = new BuilderOption();
            }
            else
            {
                option = option.Clone();
            }
            option.Partial = true;

            var count = 0;

            foreach (var item in tables)
            {
                // 跳过排除项
                if (option.Excludes.Contains(item.Name))
                {
                    continue;
                }
                if (option.Excludes.Contains(item.TableName))
                {
                    continue;
                }

                var builder = new EntityBuilder
                {
                    AllTables = tables,
                    Option    = option.Clone(),
                };

                builder.Load(item);

                builder.Execute();
                builder.Save(null, true, chineseFileName);

                builder.Business = true;
                builder.Execute();
                builder.Save(null, false, chineseFileName);

                count++;
            }

            return(count);
        }
Example #2
0
        EntityBuilder Create2(IDataTable table)
        {
            var builder = new EntityBuilder();

            builder.Table    = table;
            builder.ConnName = ConnName;
            builder.Output   = XTrace.TempPath.CombinePath(ConnName).EnsureDirectory(false);

            if (Debug)
            {
                builder.Log = XTrace.Log;
            }
            builder.CSharp = new Version(5, 0);

            builder.Execute();
            Codes.Add(builder.Save(null, true));

            builder.Business = true;
            builder.Execute();
            Codes.Add(builder.Save(null, true));

            return(builder);
        }
Example #3
0
        /// <summary>为Xml模型文件生成实体类</summary>
        /// <param name="tables">模型文件</param>
        /// <param name="output">输出目录</param>
        /// <param name="nameSpace">命名空间</param>
        /// <param name="connName">连接名</param>
        /// <param name="baseClass">基类</param>
        /// <param name="chineseFileName">是否中文名称</param>
        public static Int32 BuildTables(IList <IDataTable> tables, String output = null, String nameSpace = null, String connName = null, String baseClass = null, Boolean chineseFileName = true)
        {
            if (tables == null || tables.Count == 0)
            {
                return(0);
            }

            // 连接名
            if (connName.IsNullOrEmpty() && !nameSpace.IsNullOrEmpty() && nameSpace.Contains("."))
            {
                connName = nameSpace.Substring(nameSpace.LastIndexOf(".") + 1);
            }

            XTrace.WriteLine("代码生成:{0} 输出:{1} 命名空间:{2} 连接名:{3} 基类:{4}", tables.Count, output, nameSpace, connName, baseClass);

            var count = 0;

            foreach (var item in tables)
            {
                var builder = new EntityBuilder
                {
                    Table       = item,
                    AllTables   = tables,
                    GenericType = item.Properties["RenderGenEntity"].ToBoolean()
                };

                // 命名空间
                var str = item.Properties["Namespace"];
                if (str.IsNullOrEmpty())
                {
                    str = nameSpace;
                }
                builder.Namespace = str;

                // 连接名
                str = item.ConnName;
                if (str.IsNullOrEmpty())
                {
                    str = connName;
                }
                builder.ConnName = str;

                // 基类
                str = item.Properties["BaseClass"];
                if (str.IsNullOrEmpty())
                {
                    str = baseClass;
                }
                builder.BaseClass = str;

                if (Debug)
                {
                    builder.Log = XTrace.Log;
                }

                builder.Execute();

                // 输出目录
                str = item.Properties["Output"];
                if (str.IsNullOrEmpty())
                {
                    str = output;
                }
                builder.Output = str;
                builder.Save(null, true, chineseFileName);

                builder.Business = true;
                builder.Execute();
                builder.Save(null, false, chineseFileName);

                count++;
            }

            return(count);
        }
Example #4
0
        /// <summary>为Xml模型文件生成实体类</summary>
        /// <param name="tables">模型文件</param>
        /// <param name="option">生成可选项</param>
        /// <param name="chineseFileName">是否中文名称</param>
        public static Int32 BuildTables(IList <IDataTable> tables, BuilderOption option, Boolean chineseFileName = true)
        {
            if (tables == null || tables.Count == 0)
            {
                return(0);
            }

            if (option == null)
            {
                option = new BuilderOption();
            }
            else
            {
                option = option.Clone();
            }
            option.Partial = true;

            if (Debug)
            {
                var output = option.Output;
                if (output.IsNullOrEmpty())
                {
                    output = ".";
                }
                XTrace.WriteLine("生成实体类 {0}", output.GetBasePath());
            }

            var count = 0;

            foreach (var item in tables)
            {
                // 跳过排除项
                if (option.Excludes.Contains(item.Name))
                {
                    continue;
                }
                if (option.Excludes.Contains(item.TableName))
                {
                    continue;
                }

                var builder = new EntityBuilder
                {
                    AllTables = tables,
                    Option    = option.Clone(),
                };
                if (Debug)
                {
                    builder.Log = XTrace.Log;
                }

                builder.Load(item);

                builder.Execute();
                builder.Save(null, true, chineseFileName);

                builder.Business = true;
                builder.Execute();
                builder.Save(null, false, chineseFileName);

                count++;
            }

            return(count);
        }