コード例 #1
0
        public async Task <int> RecalculationCount(int[] categoryIds, IUnitOfWork uow = null)
        {
            string databaseName = EntityDescriptorCollection.Get <CategoryEntity>().Database;
            string addCountSql  = $"update {databaseName}category as t1 set Count=(select count(1) from topic as t2 where t2.categoryId=t1.id) where id in ({string.Join(",", categoryIds)})";

            return(await Db.ExecuteAsync(addCountSql, uow));
        }
コード例 #2
0
 public DbSet(IDbContext context)
 {
     DbContext        = context;
     EntityDescriptor = EntityDescriptorCollection.Get <TEntity>();
     _sqlAdapter      = context.Options.SqlAdapter;
     _sql             = EntityDescriptor.Sql;
 }
コード例 #3
0
        public async Task <int> AddCount(int[] categoryIds, IUnitOfWork uow = null)
        {
            string databaseName = EntityDescriptorCollection.Get <CategoryEntity>().Database;
            string addCountSql  = $"update {databaseName}category set Count=Count+1 where id in ({string.Join(",", categoryIds)})";

            return(await Db.ExecuteAsync(addCountSql, uow));
        }
コード例 #4
0
        public async Task <int> RecalculationCount(int[] tagIds, IUnitOfWork uow = null)
        {
            string tagDatabaseName = EntityDescriptorCollection.Get <TagEntity>().Database;
            string addCountSql     = $"update {tagDatabaseName}tag as t1 set t1.Count=(select count(1) from topic_Tag as t2 where t2.tagId=t1.id) where t1.id in ({string.Join(",", tagIds)})";

            return(await Db.ExecuteAsync(addCountSql, uow));
        }
コード例 #5
0
        private void LoadDictNameSyncDescriptors(IServiceCollection services, IModuleDescriptor moduleDescriptor)
        {
            var collection = new DictSyncDescriptorCollection();

            //因为EntityDescriptorCollection未提供获取所有实体描述符的方法,所以暂时只能通过模块查询
            var entityDescriptors = EntityDescriptorCollection.Get(moduleDescriptor.Code);

            foreach (var entityDescriptor in entityDescriptors)
            {
                foreach (var column in entityDescriptor.Columns)
                {
                    var attr = (DictSyncAttribute)Attribute.GetCustomAttribute(column.PropertyInfo, typeof(DictSyncAttribute));
                    if (attr != null)
                    {
                        collection.Add(new DictSyncDescriptor
                        {
                            GroupCode        = attr.GroupCode,
                            DictCode         = attr.DictCode,
                            DictNameColName  = attr.DictNameColName,
                            EntityDescriptor = entityDescriptor,
                            ColumnDescriptor = column
                        });
                    }
                }
            }

            services.AddSingleton(collection);
        }
コード例 #6
0
ファイル: DbSet.cs プロジェクト: staoran/NetModular
        public DbSet(IDbContext context)
        {
            DbContext        = context;
            EntityDescriptor = EntityDescriptorCollection.Get <TEntity>();
            _sqlAdapter      = context.Options.SqlAdapter;
            _sql             = EntityDescriptor.Sql;

            _logger = context.Options.LoggerFactory?.CreateLogger("DbSet-" + EntityDescriptor.TableName);
        }
コード例 #7
0
ファイル: DbContext.cs プロジェクト: zhxuyang11/NetModular
        public IDbSet <TEntity> Set <TEntity>() where TEntity : IEntity, new()
        {
            var descriptor = EntityDescriptorCollection.Get <TEntity>();

            if (descriptor.DbSet == null)
            {
                descriptor.DbSet = new DbSet <TEntity>(descriptor.DbContext);
            }

            return((IDbSet <TEntity>)descriptor.DbSet);
        }
コード例 #8
0
        public NetSqlQueryable(IDbSet <TEntity> dbSet, Expression <Func <TEntity, bool> > whereExpression) : base(dbSet, new QueryBody(dbSet.DbContext.Options.SqlAdapter))
        {
            QueryBody.JoinDescriptors.Add(new QueryJoinDescriptor
            {
                Type             = JoinType.UnKnown,
                Alias            = "T1",
                EntityDescriptor = EntityDescriptorCollection.Get <TEntity>(),
            });
            QueryBody.WhereDelegateType = typeof(Func <,>).MakeGenericType(typeof(TEntity), typeof(bool));

            Where(whereExpression);
        }
コード例 #9
0
        public NetSqlQueryable(IDbSet <TEntity> dbSet, Expression <Func <TEntity, bool> > whereExpression, string tableName = null, bool noLock = true) : base(dbSet, new QueryBody(dbSet.DbContext.Options.SqlAdapter))
        {
            QueryBody.JoinDescriptors.Add(new QueryJoinDescriptor
            {
                Type             = JoinType.UnKnown,
                Alias            = "T1",
                EntityDescriptor = EntityDescriptorCollection.Get <TEntity>(),
                TableName        = tableName.NotNull() ? tableName : Db.EntityDescriptor.TableName,
                NoLock           = noLock
            });

            Where(whereExpression);
        }
コード例 #10
0
        public NetSqlQueryable(IDbSet dbSet, QueryBody queryBody, Expression <Func <TEntity, TEntity2, TEntity3, bool> > onExpression, JoinType joinType = JoinType.Left) : base(dbSet, queryBody)
        {
            Check.NotNull(onExpression, nameof(onExpression), "请输入连接条件");

            QueryBody.JoinDescriptors.Add(new QueryJoinDescriptor
            {
                Type             = joinType,
                Alias            = "T3",
                EntityDescriptor = EntityDescriptorCollection.Get <TEntity3>(),
                On = onExpression
            });

            QueryBody.WhereDelegateType =
                typeof(Func <, , ,>).MakeGenericType(typeof(TEntity), typeof(TEntity2), typeof(TEntity3), typeof(bool));
        }
コード例 #11
0
        protected DbContext(IDbContextOptions options, IServiceProvider serviceProvider)
        {
            Options         = options;
            ServiceProvider = serviceProvider;
            LoginInfo       = Options.LoginInfo;

            if (options.DbOptions.CreateDatabase)
            {
                if (options.DatabaseCreateEvents != null)
                {
                    options.DatabaseCreateEvents.DbContext = this;
                }

                options.SqlAdapter.CreateDatabase(EntityDescriptorCollection.Get(options.DbModuleOptions.Name), options.DatabaseCreateEvents);
            }
        }
コード例 #12
0
        public NetSqlQueryable(IDbSet dbSet, QueryBody queryBody, Expression <Func <TEntity, TEntity2, bool> > onExpression, JoinType joinType = JoinType.Left, string tableName = null, bool noLock = false)
            : base(dbSet, queryBody)
        {
            Check.NotNull(onExpression, nameof(onExpression), "请输入连接条件");
            var t2 = new QueryJoinDescriptor
            {
                Type             = joinType,
                Alias            = "T2",
                EntityDescriptor = EntityDescriptorCollection.Get <TEntity2>(),
                On     = onExpression,
                NoLock = noLock
            };

            t2.TableName = tableName.NotNull() ? tableName : t2.EntityDescriptor.TableName;
            QueryBody.JoinDescriptors.Add(t2);
        }
コード例 #13
0
        public NetSqlQueryable(IDbSet dbSet, QueryBody queryBody, Expression <Func <TEntity, TEntity2, bool> > onExpression, JoinType joinType = JoinType.Left, string tableName = null)
            : base(dbSet, queryBody)
        {
            Check.NotNull(onExpression, nameof(onExpression), "请输入连接条件");
            var t2 = new QueryJoinDescriptor
            {
                Type             = joinType,
                Alias            = "T2",
                EntityDescriptor = EntityDescriptorCollection.Get <TEntity2>(),
                On = onExpression
            };

            t2.TableName = tableName.NotNull() ? tableName : t2.EntityDescriptor.TableName;
            QueryBody.JoinDescriptors.Add(t2);

            QueryBody.WhereDelegateType = typeof(Func <, ,>).MakeGenericType(typeof(TEntity), typeof(TEntity2), typeof(bool));
        }
コード例 #14
0
        public NetSqlQueryable(IDbSet dbSet, QueryBody queryBody, Expression <Func <TEntity, TEntity2, TEntity3, TEntity4, TEntity5, TEntity6, TEntity7, TEntity8, TEntity9, TEntity10, bool> > onExpression, JoinType joinType = JoinType.Left, string tableName = null, bool noLock = true)
            : base(dbSet, queryBody)
        {
            Check.NotNull(onExpression, nameof(onExpression), "请输入连接条件");

            var t10 = new QueryJoinDescriptor
            {
                Type             = joinType,
                Alias            = "T10",
                EntityDescriptor = EntityDescriptorCollection.Get <TEntity10>(),
                On     = onExpression,
                NoLock = noLock
            };

            t10.TableName = tableName.NotNull() ? tableName : t10.EntityDescriptor.TableName;
            QueryBody.JoinDescriptors.Add(t10);
        }
コード例 #15
0
        public NetSqlQueryable(IDbSet dbSet, QueryBody queryBody, Expression <Func <TEntity, TEntity2, TEntity3, TEntity4, TEntity5, TEntity6, TEntity7, TEntity8, TEntity9, TEntity10, bool> > onExpression, JoinType joinType = JoinType.Left, string tableName = null)
            : base(dbSet, queryBody)
        {
            Check.NotNull(onExpression, nameof(onExpression), "请输入连接条件");

            var t10 = new QueryJoinDescriptor
            {
                Type             = joinType,
                Alias            = "T10",
                EntityDescriptor = EntityDescriptorCollection.Get <TEntity10>(),
                On = onExpression,
            };

            t10.TableName = tableName.NotNull() ? tableName : t10.EntityDescriptor.TableName;
            QueryBody.JoinDescriptors.Add(t10);

            QueryBody.WhereDelegateType = typeof(Func <, , , , , , , , , ,>).MakeGenericType(typeof(TEntity), typeof(TEntity2), typeof(TEntity3),
                                                                                             typeof(TEntity4), typeof(TEntity5), typeof(TEntity6), typeof(TEntity7), typeof(TEntity8), typeof(TEntity9), typeof(TEntity10), typeof(bool));
        }
コード例 #16
0
ファイル: DbContext.cs プロジェクト: zhxuyang11/NetModular
 public void CreateDatabase()
 {
     Options.SqlAdapter.CreateDatabase(EntityDescriptorCollection.Get(Options.DbModuleOptions.Name), Options.DatabaseCreateEvents, out bool exists);
     DatabaseExists = exists;
 }