Exemple #1
0
 /// <summary>
 /// 如果提供的值是不可空的,则为查询条件添加不相等的查询判断。
 /// </summary>
 /// <param name="query">The query.</param>
 /// <param name="property">查询某个属性。</param>
 /// <param name="value">当 value 不可空时,才添加查询判断。</param>
 /// <param name="propertyOwner">The property owner.</param>
 /// <returns></returns>
 public static IPropertyQuery AddConstrainNotEqualIf(this IPropertyQuery query, IManagedProperty property, object value, Type propertyOwner = null)
 {
     if (ConditionalSql.IsNotEmpty(value))
     {
         query.AddConstrain(property, propertyOwner).NotEqual(value);
     }
     return(query);
 }
Exemple #2
0
 /// <summary>
 /// 直接添加某个 Sql 查询条件。
 /// 如果没有相应的 And 连接符,则自动添加。
 /// </summary>
 /// <param name="query">The query.</param>
 /// <param name="formatSql">The format SQL.</param>
 /// <param name="parameters">The parameters.</param>
 /// <returns></returns>
 public static IPropertyQuery AddConstrainSql(this IPropertyQuery query, string formatSql, params object[] parameters)
 {
     if (query.HasWhere && query.IsCompleted)
     {
         query.And();
     }
     return(query.ConstrainSql(formatSql, parameters));
 }
Exemple #3
0
 /// <summary>
 /// 直接添加某个查询条件。
 /// 如果没有相应的 And 连接符,则自动添加。
 /// </summary>
 /// <param name="query">The query.</param>
 /// <param name="property">The property.</param>
 /// <param name="propertyOwner">The property owner.</param>
 /// <returns></returns>
 public static IPropertyQueryValue AddConstrain(this IPropertyQuery query, IManagedProperty property, Type propertyOwner = null)
 {
     if (query.HasWhere && query.IsCompleted)
     {
         query.And();
     }
     return(query.Constrain(property, propertyOwner));
 }
Exemple #4
0
 /// <summary>
 /// 如果提供的值是不可空的,则为查询条件添加是否为起始字符串的查询判断。
 /// </summary>
 /// <param name="query">The query.</param>
 /// <param name="property">查询某个属性。</param>
 /// <param name="value">当 value 不可空时,才添加查询判断。</param>
 /// <param name="propertyOwner">The property owner.</param>
 /// <returns></returns>
 public static IPropertyQuery AddConstrainStartWithIf(this IPropertyQuery query, IManagedProperty property, string value, Type propertyOwner = null)
 {
     if (ConditionalSql.IsNotEmpty(value))
     {
         query.AddConstrain(property, propertyOwner).StartWith(value);
     }
     return(query);
 }
Exemple #5
0
        /// <summary>
        /// 通过托管属性查询条件来查询数据库,把满足条件的实体查询出来。
        /// </summary>
        /// <param name="propertyQuery">托管属性查询条件。</param>
        /// <returns></returns>
        protected EntityList QueryList(IPropertyQuery propertyQuery)
        {
            var args = new PropertyQueryArgs
            {
                PropertyQuery = propertyQuery
            };

            return(this.QueryList(args));
        }
Exemple #6
0
        public void QueriesWillMatchProvidedParameters()
        {
            // Arrange
            var expectedResult = new IPropertyQuery[]
            {
                new DelegatingPropertyQuery(),
                new DelegatingPropertyQuery()
            };
            var sut = new AndPropertyQuery(expectedResult);

            // Act
            var result = sut.Queries;

            // Assert
            Assert.True(expectedResult.SequenceEqual(result));
        }
Exemple #7
0
        /// <summary>
        /// 把老的 IPropertyQuery 对象,转换为新版本的 IQuery 对象。
        /// </summary>
        /// <param name="propertyQuery">The property query.</param>
        /// <returns></returns>
        /// <exception cref="System.NotSupportedException"></exception>
        protected IQuery ConvertToQuery(IPropertyQuery propertyQuery)
        {
            var table = qf.Table(this);
            var query = qf.Query(table);

            //转换 From
            var dbQuery = propertyQuery as PropertyQuery;

            if (dbQuery.HasInnerJoin)
            {
                foreach (var refItem in dbQuery.RefItems)
                {
                    if (refItem.JoinRefType == JoinRefType.QueryData)
                    {
                        throw new NotSupportedException();
                    }

                    var refTable = qf.Table(refItem.RefTable.Repository);
                    query.From = qf.Join(query.From, refTable, refItem.RefProperty);
                }
            }

            //转换 Where
            var converter = new ConstraintConverter();

            converter.Query = query;
            converter.Convert(dbQuery.Where as Constraint);

            //转换 OrderBy
            for (int i = 0, c = dbQuery.Orders.Count; i < c; i++)
            {
                var order = dbQuery.Orders[i];
                var dir   = order.Ascending ? OrderDirection.Ascending : OrderDirection.Descending;
                query.OrderBy.Add(qf.OrderBy(table.Column(order.Property), dir));
            }

            return(query);
        }
        /// <summary>
        /// 把老的 IPropertyQuery 对象,转换为新版本的 IQuery 对象。
        /// </summary>
        /// <param name="propertyQuery">The property query.</param>
        /// <returns></returns>
        /// <exception cref="System.NotSupportedException"></exception>
        protected IQuery ConvertToQuery(IPropertyQuery propertyQuery)
        {
            var table = qf.Table(this);
            var query = qf.Query(table);

            //转换 From
            var dbQuery = propertyQuery as PropertyQuery;

            if (dbQuery.HasInnerJoin)
            {
                foreach (var refItem in dbQuery.RefItems)
                {
                    if (refItem.JoinRefType == JoinRefType.QueryData)
                    {
                        throw new NotSupportedException();
                    }

                    var refTable = qf.Table(refItem.RefTable.Repository);
                    query.From = qf.Join(query.From, refTable, refItem.RefProperty);
                }
            }

            //转换 Where
            var converter = new ConstraintConverter();
            converter.Query = query;
            converter.Convert(dbQuery.Where as Constraint);

            //转换 OrderBy
            for (int i = 0, c = dbQuery.Orders.Count; i < c; i++)
            {
                var order = dbQuery.Orders[i];
                var dir = order.Ascending ? OrderDirection.Ascending : OrderDirection.Descending;
                query.OrderBy.Add(qf.OrderBy(table.Column(order.Property), dir));
            }

            return query;
        }
        /// <summary>
        /// 通过托管属性查询条件来查询数据库,把满足条件的实体查询出来。
        /// </summary>
        /// <param name="propertyQuery">托管属性查询条件。</param>
        /// <returns></returns>
        protected EntityList QueryList(IPropertyQuery propertyQuery)
        {
            var args = new PropertyQueryArgs
            {
                PropertyQuery = propertyQuery
            };

            return this.QueryList(args);
        }
 public PropertyController(IPropertyQuery propertyQuery, IPropertyCommand propertyCommand)
 {
     this.propertyQuery   = propertyQuery;
     this.propertyCommand = propertyCommand;
 }
 /// <summary>
 /// Constructs an instance of <see cref="ReadonlyCollectionPropertiesBehavior"/>, used to decorate an
 /// <see cref="ISpecimenBuilder"/> with a <see cref="Postprocessor"/> which invokes
 /// <see cref="ReadonlyCollectionPropertiesCommand"/> if the specimen meets the
 /// <see cref="ReadonlyCollectionPropertiesSpecification"/>.
 /// </summary>
 /// <param name="propertyQuery">The query that will be applied to select readonly collection properties.</param>
 public ReadonlyCollectionPropertiesBehavior(IPropertyQuery propertyQuery)
 {
     this.PropertyQuery = propertyQuery;
 }
 /// <summary>
 /// Constructs an instance of <see cref="ReadonlyCollectionPropertiesSpecification"/>, which will use the query
 /// supplied in <paramref name="propertyQuery"/> to determine whether or not a type contains readonly collection
 /// properties.
 /// </summary>
 /// <param name="propertyQuery">The query that will be applied to select readonly collection properties.</param>
 public ReadonlyCollectionPropertiesSpecification(IPropertyQuery propertyQuery)
 {
     this.PropertyQuery = propertyQuery;
 }
 /// <summary>
 /// Constructs an instance of <see cref="ReadonlyCollectionPropertiesCommand"/>, used to fill all readonly
 /// properties in a specimen that implement <see cref="ICollection{T}"/>.
 /// </summary>
 /// <param name="propertyQuery">The query that will be applied to select readonly collection properties.</param>
 public ReadonlyCollectionPropertiesCommand(IPropertyQuery propertyQuery)
 {
     this.PropertyQuery = propertyQuery;
 }