Ejemplo n.º 1
0
        public static bool DbInsert(this TUserBasicInfo entity, DbSession session)
        {
            var           query   = IORMProvider.GetDbQueryBuilder(session);
            InsertBuilder builder = new InsertBuilder();

            builder.ComponentInsert.Add(new ComponentValueOfInsert(TUserBasicInfoProperties.UserId, entity.UserId));
            builder.ComponentInsert.Add(new ComponentValueOfInsert(TUserBasicInfoProperties.Gender, entity.Gender));
            if (entity.Birthday.HasValue)
            {
                builder.ComponentInsert.Add(new ComponentValueOfInsert(TUserBasicInfoProperties.Birthday, entity.Birthday.Value));
            }
            if (entity.Mobile.HasValue)
            {
                builder.ComponentInsert.Add(new ComponentValueOfInsert(TUserBasicInfoProperties.Mobile, entity.Mobile.Value));
            }
            if (entity.Email == null)
            {
                throw new NotImplementedException("缺少必填的参数项值, 参数项: " + nameof(entity.Email));
            }
            builder.ComponentInsert.Add(new ComponentValueOfInsert(TUserBasicInfoProperties.Email, entity.Email));
            if (entity.IdCardNumber == null)
            {
                throw new NotImplementedException("缺少必填的参数项值, 参数项: " + nameof(entity.IdCardNumber));
            }
            builder.ComponentInsert.Add(new ComponentValueOfInsert(TUserBasicInfoProperties.IdCardNumber, entity.IdCardNumber));
            query.InsertBuilders.Add(builder);
            return(IORMProvider.GetQueryOperator(session).Insert <TUserBasicInfo>(session, query));
        }
Ejemplo n.º 2
0
        public static bool FetchTUser(this TUserBasicInfo tUserBasicInfo, DbSession session)
        {
            var           query   = IORMProvider.GetDbQueryBuilder(session);
            SelectBuilder builder = new SelectBuilder();

            if (tUserBasicInfo.UserId == Guid.Empty)
            {
                var subselect = new SelectBuilder();
                subselect.TableName = nameof(TUserBasicInfo);
                subselect.ComponentSelect.Add(TUserBasicInfoProperties.UserId);
                subselect.ComponentWhere.Add(new ComponentValueOfWhere(TUserBasicInfoProperties.UserId, tUserBasicInfo.UserId, LocateType.Equal));
                builder.ComponentWhere.Add(new ComponentValueOfWhere(TUserProperties.UserId, subselect, LocateType.Equal));
            }
            else
            {
                builder.ComponentWhere.Add(new ComponentValueOfWhere(TUserProperties.UserId, tUserBasicInfo.UserId, LocateType.Equal));
            }
            query.SelectBuilders.Add(builder);
            tUserBasicInfo.User = IORMProvider.GetQueryOperator(session).Select <TUser>(session, query);
            if (tUserBasicInfo.User == null)
            {
                throw new NotImplementedException(string.Format("1..* 关联未查询到匹配数据, Parent:{0}; Child: {1}", nameof(TUserBasicInfo), nameof(TUser)));
            }
            return(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 未查询到数据时返回 null
        /// </summary>
        public static TUserBasicInfo DbSelect(this TUserBasicInfo entity, DbSession session, params PDMDbProperty[] fields)
        {
            var           query   = IORMProvider.GetDbQueryBuilder(session);
            SelectBuilder builder = new SelectBuilder();

            if (fields.Count() == 0)
            {
                builder.ComponentSelect.Add(TUserBasicInfoProperties.UserId);
                builder.ComponentSelect.Add(TUserBasicInfoProperties.Gender);
                builder.ComponentSelect.Add(TUserBasicInfoProperties.Birthday);
                builder.ComponentSelect.Add(TUserBasicInfoProperties.Mobile);
                builder.ComponentSelect.Add(TUserBasicInfoProperties.Email);
                builder.ComponentSelect.Add(TUserBasicInfoProperties.IdCardNumber);
            }
            else
            {
                builder.ComponentSelect.Add(TUserBasicInfoProperties.UserId);
                foreach (var field in fields)
                {
                    builder.ComponentSelect.Add(field);
                }
            }
            builder.ComponentWhere.Add(new ComponentValueOfWhere(TUserBasicInfoProperties.UserId, entity.UserId, LocateType.Equal));
            query.SelectBuilders.Add(builder);
            return(IORMProvider.GetQueryOperator(session).Select <TUserBasicInfo>(session, query));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 未查询到数据时返回 null
        /// </summary>
        public static TUserBasicInfo DbSelect(this TUserBasicInfo entity, DbSession session, SelectBuilder select)
        {
            var query = IORMProvider.GetDbQueryBuilder(session);

            query.SelectBuilder = select;
            return(IORMProvider.GetQueryOperator(session).Select <TUserBasicInfo>(session, query));
        }
Ejemplo n.º 5
0
        public static bool DbDelete(this TUserBasicInfo entity, DbSession session)
        {
            var query = IORMProvider.GetDbQueryBuilder(session);

            query.DeleteBuilder.ComponentWhere.Add(new ComponentValueOfWhere(TUserBasicInfoProperties.UserId, entity.UserId, LocateType.Equal));
            return(IORMProvider.GetQueryOperator(session).Delete <TUserBasicInfo>(session, query));
        }
Ejemplo n.º 6
0
        public static bool DbUpdate(this TUserBasicInfo entity, DbSession session, params PDMDbProperty[] fields)
        {
            var           query   = IORMProvider.GetDbQueryBuilder(session);
            UpdateBuilder builder = new UpdateBuilder();

            builder.ComponentWhere.Add(new ComponentValueOfWhere(TUserBasicInfoProperties.UserId, entity.UserId, LocateType.Equal));
            if (fields == null || fields.Length == 0)
            {
                builder.ComponentSet.Add(new ComponentValueOfSet(TUserBasicInfoProperties.UserId, entity.UserId));
                builder.ComponentSet.Add(new ComponentValueOfSet(TUserBasicInfoProperties.Gender, entity.Gender));
                builder.ComponentSet.Add(new ComponentValueOfSet(TUserBasicInfoProperties.Birthday, entity.Birthday));
                builder.ComponentSet.Add(new ComponentValueOfSet(TUserBasicInfoProperties.Mobile, entity.Mobile));
                builder.ComponentSet.Add(new ComponentValueOfSet(TUserBasicInfoProperties.Email, entity.Email));
                builder.ComponentSet.Add(new ComponentValueOfSet(TUserBasicInfoProperties.IdCardNumber, entity.IdCardNumber));
            }
            else
            {
                if (fields.Contains(TUserBasicInfoProperties.Gender))
                {
                    builder.ComponentSet.Add(new ComponentValueOfSet(TUserBasicInfoProperties.Gender, entity.Gender));
                }
                if (fields.Contains(TUserBasicInfoProperties.Birthday))
                {
                    builder.ComponentSet.Add(new ComponentValueOfSet(TUserBasicInfoProperties.Birthday, entity.Birthday));
                }
                if (fields.Contains(TUserBasicInfoProperties.Mobile))
                {
                    builder.ComponentSet.Add(new ComponentValueOfSet(TUserBasicInfoProperties.Mobile, entity.Mobile));
                }
                if (fields.Contains(TUserBasicInfoProperties.Email))
                {
                    builder.ComponentSet.Add(new ComponentValueOfSet(TUserBasicInfoProperties.Email, entity.Email));
                }
                if (fields.Contains(TUserBasicInfoProperties.IdCardNumber))
                {
                    builder.ComponentSet.Add(new ComponentValueOfSet(TUserBasicInfoProperties.IdCardNumber, entity.IdCardNumber));
                }
            }
            query.UpdateBuilders.Add(builder);
            return(IORMProvider.GetQueryOperator(session).Update <TUserBasicInfo>(session, query));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 存在相应对象时返回true,缺少对象时返回false
        /// </summary>
        public static bool DbLoad(this TUserBasicInfo entity, DbSession session, params PDMDbProperty[] fields)
        {
            var result = entity.DbSelect(session, fields);

            if (result == null)
            {
                return(false);
            }
            if (fields.Count() == 0)
            {
                entity.Gender       = result.Gender;
                entity.Birthday     = result.Birthday;
                entity.Mobile       = result.Mobile;
                entity.Email        = result.Email;
                entity.IdCardNumber = result.IdCardNumber;
            }
            else
            {
                if (fields.Contains(TUserBasicInfoProperties.Gender))
                {
                    entity.Gender = result.Gender;
                }
                if (fields.Contains(TUserBasicInfoProperties.Birthday))
                {
                    entity.Birthday = result.Birthday;
                }
                if (fields.Contains(TUserBasicInfoProperties.Mobile))
                {
                    entity.Mobile = result.Mobile;
                }
                if (fields.Contains(TUserBasicInfoProperties.Email))
                {
                    entity.Email = result.Email;
                }
                if (fields.Contains(TUserBasicInfoProperties.IdCardNumber))
                {
                    entity.IdCardNumber = result.IdCardNumber;
                }
            }
            return(true);
        }