Ejemplo n.º 1
0
        /// <summary>为数据模型创建实体程序集,无缓存</summary>
        /// <param name="name">程序集名</param>
        /// <param name="connName">连接名</param>
        /// <param name="tables">模型表</param>
        /// <returns></returns>
        public static EntityAssembly Create(String name, String connName, List <IDataTable> tables)
        {
            if (String.IsNullOrEmpty(name))
            {
                return(null);
            }
            if (tables == null)
            {
                return(null);
            }

            var asm = new EntityAssembly();

            asm.Name     = name;
            asm.ConnName = connName;
            asm.Tables   = tables;
            asm.CreateAll();

            asm.Compile();

            return(asm);
        }
Ejemplo n.º 2
0
        /// <summary>为数据模型创建实体程序集,带缓存,依赖于表和字段名称,不依赖名称以外的信息。</summary>
        /// <param name="name"></param>
        /// <param name="tables"></param>
        /// <returns></returns>
        public static EntityAssembly CreateWithCache(String name, List <IDataTable> tables)
        {
            if (String.IsNullOrEmpty(name))
            {
                return(null);
            }
            if (tables == null)
            {
                return(null);
            }

            // 构建缓存Key
            var sb = new StringBuilder();

            sb.Append(name);
            foreach (var item in tables)
            {
                sb.Append("|");
                sb.Append(item.Name);
                foreach (var dc in item.Columns)
                {
                    sb.Append(",");
                    sb.Append(dc.Name);
                }
            }
            var key = DataHelper.Hash(sb.ToString());

            return(cache.GetItem <String, List <IDataTable> >(key, name, tables, (k, n, ts) =>
            {
                var asm = new EntityAssembly();
                asm.Name = n;
                asm.Tables = ts;
                asm.CreateAll();

                asm.Compile();
                return asm;
            }));
        }
Ejemplo n.º 3
0
        /// <summary>为数据模型创建实体程序集,无缓存</summary>
        /// <param name="name">程序集名</param>
        /// <param name="connName">连接名</param>
        /// <param name="tables">模型表</param>
        /// <returns></returns>
        public static EntityAssembly Create(String name, String connName, List<IDataTable> tables)
        {
            if (String.IsNullOrEmpty(name)) return null;
            if (tables == null) return null;

            var asm = new EntityAssembly();
            asm.Name = name;
            asm.ConnName = connName;
            asm.Tables = tables;
            asm.CreateAll();

            asm.Compile();

            return asm;
        }
Ejemplo n.º 4
0
        /// <summary>为数据模型创建实体程序集,带缓存,依赖于表和字段名称,不依赖名称以外的信息。</summary>
        /// <param name="name"></param>
        /// <param name="tables"></param>
        /// <returns></returns>
        public static EntityAssembly CreateWithCache(String name, List<IDataTable> tables)
        {
            if (String.IsNullOrEmpty(name)) return null;
            if (tables == null) return null;

            // 构建缓存Key
            var sb = new StringBuilder();
            sb.Append(name);
            foreach (var item in tables)
            {
                sb.Append("|");
                sb.Append(item.Name);
                foreach (var dc in item.Columns)
                {
                    sb.Append(",");
                    sb.Append(dc.Name);
                }
            }
            var key = DataHelper.Hash(sb.ToString());

            return cache.GetItem<String, List<IDataTable>>(key, name, tables, (k, n, ts) =>
            {
                var asm = new EntityAssembly();
                asm.Name = n;
                asm.Tables = ts;
                asm.CreateAll();

                asm.Compile();
                return asm;
            });
        }