/// <summary> /// Initializes a new instance of the <see cref="MorphableFlowQueryBase{TSource,TQuery}" /> class. /// </summary> /// <param name="criteriaFactory"> /// The criteria factory. /// </param> /// <param name="alias"> /// The alias. /// </param> /// <param name="options"> /// The options. /// </param> /// <param name="query"> /// The query. /// </param> /// <exception cref="ArgumentException"> /// The "this" reference is not of the type <see cref="T:TQuery" /> as specified by /// <typeparamref name="TQuery" />. /// </exception> /// <exception cref="ArgumentNullException"> /// <paramref name="criteriaFactory" /> is null and the specific query alteration is not an implementation /// of <see cref="T:IDetachedFlowQuery{TSource}" />. /// </exception> protected MorphableFlowQueryBase ( Func <Type, string, ICriteria> criteriaFactory, string alias = null, FlowQueryOptions options = null, IMorphableFlowQuery query = null ) : base(criteriaFactory, alias, options, query) { if (query != null) { CommentValue = query.CommentValue; Constructor = query.Constructor; FetchSizeValue = query.FetchSizeValue; IsDistinct = query.IsDistinct; IsReadOnly = query.IsReadOnly; if (query.Mappings != null) { Mappings = query.Mappings.ToDictionary(x => x.Key, x => x.Value); } Projection = query.Projection; ResultTransformer = query.ResultTransformer; TimeoutValue = query.TimeoutValue; } }
/// <summary> /// Initializes a new instance of the <see cref="ImmediateFlowQueryBase{TSource,TQuery}" /> class. /// </summary> /// <param name="criteriaFactory"> /// The criteria factory. /// </param> /// <param name="alias"> /// The alias. /// </param> /// <param name="options"> /// The options. /// </param> /// <param name="query"> /// The query. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="criteriaFactory" /> is null. /// </exception> protected ImmediateFlowQueryBase ( Func <Type, string, ICriteria> criteriaFactory, string alias = null, FlowQueryOptions options = null, IMorphableFlowQuery query = null ) : base(criteriaFactory, alias, options, query) { }
/// <summary> /// Initializes a new instance of the <see cref="StreamedFlowQuery{TSource}" /> class. /// </summary> /// <param name="criteriaFactory"> /// The criteria factory. /// </param> /// <param name="alias"> /// The alias. /// </param> /// <param name="options"> /// The options. /// </param> /// <param name="query"> /// The query. /// </param> /// <exception cref="System.ArgumentNullException"> /// <paramref name="criteriaFactory" /> is null. /// </exception> protected internal StreamedFlowQuery ( Func <Type, string, ICriteria> criteriaFactory, string alias = null, FlowQueryOptions options = null, IMorphableFlowQuery query = null ) : base(criteriaFactory, alias, options, query) { }
public virtual void ConstructionExample3WithOptions() { var options = new FlowQueryOptions(); options.Add(criteria => criteria.SetCacheMode(CacheMode.Refresh)); IImmediateFlowQuery <UserEntity> query = Session.FlowQuery <UserEntity>(options); Assert.That(query, Is.Not.Null); }
internal DummyQuery2 ( Func <Type, string, ICriteria> criteriaFactory, string alias = null, FlowQueryOptions options = null, IMorphableFlowQuery query = null ) : base(criteriaFactory, alias, options, query) { }
public virtual void ConstructionExample4WithAliasAndOptions() { UserEntity alias = null; var options = new FlowQueryOptions(); options.Add(criteria => criteria.SetCacheMode(CacheMode.Refresh)); IImmediateFlowQuery <UserEntity> query = Session.FlowQuery(() => alias, options); Assert.That(query, Is.Not.Null); }
public void CanCreateDetachedFlowQueryWithOptions() { FlowQueryOptions options = new FlowQueryOptions() .Add(c => c.SetMaxResults(5)); var q = Session.DetachedFlowQuery <UserEntity>(options) as DetachedFlowQuery <UserEntity>; Assert.That(q, Is.Not.Null); DetachedCriteria criteria = new CriteriaBuilder() .Build <UserEntity>(q); Assert.That(criteria.GetRootEntityTypeIfAvailable(), Is.EqualTo(typeof(UserEntity))); }
public void CanCreateDelayedFlowQueryWithOptions() { FlowQueryOptions options = new FlowQueryOptions() .Add(c => c.SetMaxResults(5)); IDelayedFlowQuery <UserEntity> q = Session.DelayedFlowQuery <UserEntity>(options); Assert.That(q, Is.Not.Null); ICriteria criteria = new CriteriaBuilder() .Build <UserEntity, UserEntity>(QuerySelection.Create(q as IQueryableFlowQuery)); Assert.That(criteria.GetRootEntityTypeIfAvailable(), Is.EqualTo(typeof(UserEntity))); }
public void CanSetCriteriaBuilderOnPerQueryOptionsUsingDelayedQuery() { var options = new FlowQueryOptions { CriteriaBuilder = new DummyCriteriaBuilder() }; Assert .That ( () => Session.DelayedFlowQuery <UserEntity>(options).Select(), Throws.InstanceOf <NotImplementedException>() ); }
public void CanCreateTrulyDetachedQueryUsingStaticHelperWithOnlyOptions() { var options = new FlowQueryOptions(); var query = DetachedFlowQuery.For <UserEntity>(options) .Where(x => x.Id == 1) .Select(x => x.Id); Assert.That(query, Is.Not.Null); Assert.That(((IFlowQuery)query).Options, Is.Not.Null); Assert.That(((IFlowQuery)query).Alias, Is.EqualTo("this")); Assert.That(((IFlowQuery)query).CriteriaFactory, Is.Null); Assert.That(query.Criteria, Is.Not.Null); }
public void Example2LocalSuppression() { var options = new FlowQueryOptions { ShouldSuppressOrderByProjectionErrors = true }; FlowQuerySelection <UserDto> users = Session.FlowQuery <UserEntity>(options) .OrderBy <UserDto>(x => x.Fullname) .Select(x => new UserDto { Fullname = x.Firstname + " " + x.Lastname }); Assert.That(users.Count(), Is.EqualTo(4)); }
public void CanCreateTrulyDetachedQueryUsingStaticHelperWithBothAliasAndOptions() { var options = new FlowQueryOptions(); UserEntity user = null; var query = DetachedFlowQuery.For(() => user, options) .Where(x => x.Id == 1) .Select(x => x.Id); Assert.That(query, Is.Not.Null); Assert.That(((IFlowQuery)query).Options, Is.Not.Null); Assert.That(((IFlowQuery)query).Alias, Is.EqualTo("user")); Assert.That(((IFlowQuery)query).CriteriaFactory, Is.Null); Assert.That(query.Criteria, Is.Not.Null); }
public void CanSetCriteriaBuilderOnPerQueryOptionsUsingDetachedQuery() { var options = new FlowQueryOptions { CriteriaBuilder = new DummyCriteriaBuilder() }; var query = Session.DetachedFlowQuery <UserEntity>(options) .Where(x => x.Id == 1) .Select(x => x.Id); Assert .That ( () => query.Criteria, Throws.InstanceOf <NotImplementedException>() ); }
/// <summary> /// Initializes a new instance of the <see cref="FlowQueryBase{TSource,TQuery}" /> class. /// </summary> /// <param name="criteriaFactory"> /// The criteria factory. /// </param> /// <param name="alias"> /// The alias. /// </param> /// <param name="options"> /// The options. /// </param> /// <param name="query"> /// The query. /// </param> /// <exception cref="ArgumentException"> /// The "this" reference is not of the type <see cref="T:TQuery" /> as specified by /// <typeparamref name="TQuery" />. /// </exception> /// <exception cref="ArgumentNullException"> /// <paramref name="criteriaFactory" /> is null and the specific query alteration is not an implementation /// of <see cref="T:IDetachedFlowQuery{TSource}" />. /// </exception> protected internal FlowQueryBase ( Func <Type, string, ICriteria> criteriaFactory, string alias = null, FlowQueryOptions options = null, IFlowQuery query = null ) : base(alias, query) { if (criteriaFactory == null) { // TODO: To allow for extensions the null-check should perhaps be pushed down the inheritance chain? // allow criteria factory to be null for detached queries. if (!(this is IDetachedFlowQuery <TSource>)) { throw new ArgumentNullException("criteriaFactory"); } } if (query != null) { CacheMode = query.CacheMode; CacheRegion = query.CacheRegion; IsCacheable = query.IsCacheable; Fetches = query.Fetches.ToList(); GroupBys = query.GroupBys.ToList(); Locks = query.Locks.ToList(); Orders = query.Orders.ToList(); ResultsToSkip = query.ResultsToSkip; ResultsToTake = query.ResultsToTake; } else { Fetches = new List <Fetch>(); GroupBys = new List <FqGroupByProjection>(); Locks = new List <Lock>(); Orders = new List <OrderByStatement>(); } CriteriaFactory = criteriaFactory; Options = options; }
public void OrderByProjectionWithoutProjectingThePropertyThrowsNothingIfErrorsAreSuppressedNonGlobally() { FlowQueryOptions options = new FlowQueryOptions() .SuppressOrderByProjectionErrors(); Assert .That ( () => { Session.FlowQuery <UserEntity>(options) .OrderBy <UserDto>(x => x.SomeValue) .Select(x => new UserDto { Username = x.Firstname }); }, Throws.Nothing ); }
/// <summary> /// Initializes a new instance of the <see cref="DetachedFlowQuery{TSource}" /> class. /// </summary> /// <param name="criteriaFactory"> /// The criteria factory. /// </param> /// <param name="alias"> /// The alias. /// </param> /// <param name="options"> /// The options. /// </param> /// <param name="query"> /// The query. /// </param> protected internal DetachedFlowQuery ( Func <Type, string, ICriteria> criteriaFactory, string alias = null, FlowQueryOptions options = null, IMorphableFlowQuery query = null ) : base(criteriaFactory, alias, options, query) { if (Constructor != null) { if (Orders.Any(x => !x.IsBasedOnSource)) { var newOrders = OrderHelper.GetSourceBasedOrdersFrom(Orders.ToArray(), Constructor, Data); Orders.Clear(); Orders.AddRange(newOrders); } } }
public void DetachedDoesNotThrowWhenOptionsIsNull() { FlowQueryOptions options = null; Assert.That(() => Session.DetachedFlowQuery <UserEntity>(options), Throws.Nothing); }
public void ImmediateDoesNotThrowWhenOptionsIsNull() { FlowQueryOptions options = null; Assert.That(() => Session.ImmediateFlowQuery <UserEntity>(options), Throws.Nothing); }