public static int CountQueryResult(QueryOver<Event> query) { using (ISession session = NHibernateHelper.OpenSession()) { return query.GetExecutableQueryOver(session).Select(Projections.Count<Event>(e => e.EventId)).RowCount(); } }
public IList <Pessoa> ListarPessoasNaoInscritasEventoPeloNomePessoa(int idEvento, string nome) { var subConsulta = QueryOver.Of <Inscricao>() .Where(inscricao => inscricao.Evento.Id == idEvento) .Select(inscricao => inscricao.Pessoa.Id); return(mSessao.QueryOver <Pessoa>() .Where(pessoa => pessoa.Nome.Upper().IsLike(nome.ToUpper(), MatchMode.Anywhere)) .WithSubquery.WhereProperty(pessoa => pessoa.Id).NotIn <Inscricao>(subConsulta) .List()); }
/// <summary> /// <paramref name="period"/>의 구간이 엔티티의 상하한 구간 (<paramref name="loExpr"/> ~ <paramref name="hiExpr"/> )과 겹치는지 검사하는 질의어를 추가합니다. /// </summary> /// <typeparam name="TRoot"></typeparam> /// <typeparam name="TSub"></typeparam> /// <param name="queryOver">QueryOver 인스턴스</param> /// <param name="period">검색 기간</param> /// <param name="loExpr">하한 값 표현식</param> /// <param name="hiExpr">상한 값 표현식</param> /// <returns></returns> public static QueryOver <TRoot, TSub> AddIsOverlap <TRoot, TSub>( this QueryOver <TRoot, TSub> queryOver, ITimePeriod period, Expression <Func <TSub, object> > loExpr, Expression <Func <TSub, object> > hiExpr) { queryOver.ShouldNotBeNull("queryOver"); queryOver.UnderlyingCriteria.Add(IsOverlapCriterion(period, loExpr, hiExpr)); return(queryOver); }
/// <summary> /// The refresh data. /// </summary> public void RefreshData() { this.badgeProgressService.Refresh(); var badges = this.DatabaseSession.QueryOver <Badge>() .Where(x => !x.Awardable) .List() .Select(x => this.badgeProgressService.GetProgress(x)) .ToList(); var awardedBadges = this.DatabaseSession.QueryOver <BadgeAward>().Where(x => x.Agent == this.LoginService.Agent).List(); this.BlackCount = badges.Count(x => x.CurrentLevel == BadgeLevel.Black) + awardedBadges.Count(x => x.Level == BadgeLevel.Black); this.PlatinumCount = this.BlackCount + badges.Count(x => x.CurrentLevel == BadgeLevel.Platinum) + awardedBadges.Count(x => x.Level == BadgeLevel.Platinum); this.GoldCount = this.PlatinumCount + badges.Count(x => x.CurrentLevel == BadgeLevel.Gold) + awardedBadges.Count(x => x.Level == BadgeLevel.Gold); this.SilverCount = this.GoldCount + badges.Count(x => x.CurrentLevel == BadgeLevel.Silver) + awardedBadges.Count(x => x.Level == BadgeLevel.Silver); this.BronzeCount = this.SilverCount + badges.Count(x => x.CurrentLevel == BadgeLevel.Bronze) + awardedBadges.Count(x => x.Level == BadgeLevel.Bronze); var agent = this.LoginService.Agent; Stat apstat = this.DatabaseSession.QueryOver <Stat>().Where(s => s.IsAccessPointsStat).SingleOrDefault(); QueryOver <ValueEntry, ValueEntry> newestStat = QueryOver.Of <ValueEntry>() .SelectList(p => p.SelectMax(x => x.Timestamp)) .Where(c => c.Agent == agent && c.Statistic == apstat); ValueEntry value = this.DatabaseSession.QueryOver <ValueEntry>() .Where(c => c.Agent == agent && c.Statistic == apstat) .WithSubquery.Where(x => x.Timestamp == newestStat.As <DateTime>()) .SingleOrDefault(); this.AccessPoints = value == null ? 0 : value.Value.Value; var currentLevel = this.levelProgressService.GetCurrentLevel( this.AccessPoints, this.SilverCount, this.GoldCount, this.PlatinumCount, this.BlackCount); var nextLevel = this.levelProgressService.GetNextLevel(currentLevel); this.Level = currentLevel.LevelNumber; this.MaxAP = nextLevel.AccessPoints; }
/// <summary> /// Executes the specified request. /// </summary> /// <param name="request">The request.</param> /// <returns>A list of blog posts</returns> public BlogsGridViewModel <SiteSettingBlogPostViewModel> Execute(BlogsFilter request) { request.SetDefaultSortingOptions("Title"); BlogPost alias = null; SiteSettingBlogPostViewModel modelAlias = null; var query = UnitOfWork.Session .QueryOver(() => alias) .Where(() => !alias.IsDeleted && alias.Status != PageStatus.Preview); if (!request.IncludeArchived) { query = query.Where(() => !alias.IsArchived); } if (!string.IsNullOrWhiteSpace(request.SearchQuery)) { var searchQuery = string.Format("%{0}%", request.SearchQuery); query = query.Where(Restrictions.InsensitiveLike(Projections.Property(() => alias.Title), searchQuery)); } if (request.CategoryId.HasValue) { query = query.Where(Restrictions.Eq(Projections.Property(() => alias.Category.Id), request.CategoryId.Value)); } if (request.Tags != null) { foreach (var tagKeyValue in request.Tags) { var id = tagKeyValue.Key.ToGuidOrDefault(); query = query.WithSubquery.WhereExists(QueryOver.Of <PageTag>().Where(tag => tag.Tag.Id == id && tag.Page.Id == alias.Id).Select(tag => 1)); } } query = query .SelectList(select => select .Select(() => alias.Id).WithAlias(() => modelAlias.Id) .Select(() => alias.Title).WithAlias(() => modelAlias.Title) .Select(() => alias.CreatedOn).WithAlias(() => modelAlias.CreatedOn) .Select(() => alias.ModifiedOn).WithAlias(() => modelAlias.ModifiedOn) .Select(() => alias.ModifiedByUser).WithAlias(() => modelAlias.ModifiedByUser) .Select(() => alias.Status).WithAlias(() => modelAlias.PageStatus) .Select(() => alias.Version).WithAlias(() => modelAlias.Version) .Select(() => alias.PageUrl).WithAlias(() => modelAlias.PageUrl)) .TransformUsing(Transformers.AliasToBean <SiteSettingBlogPostViewModel>()); var count = query.ToRowCountFutureValue(); var blogPosts = query.AddSortingAndPaging(request).Future <SiteSettingBlogPostViewModel>(); return(new BlogsGridViewModel <SiteSettingBlogPostViewModel>(blogPosts.ToList(), request, count.Value, categoryService.GetCategories())); }
protected DetachedCriteria ToDetachedCriteria <T>(QueryOver <T> actual) { ICriteria criteria = actual.UnderlyingCriteria; CriteriaImpl criteriaImpl = (CriteriaImpl) typeof(QueryOver <T>).GetField("impl", BindingFlags.NonPublic | BindingFlags.Instance) .GetValue(actual); return((DetachedCriteria) typeof(DetachedCriteria).GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, new System.Type[] { typeof(CriteriaImpl), typeof(ICriteria) }, null) .Invoke(new object[] { criteriaImpl, criteria })); }
public int GetMaximoNumeroEscuela() { var criterioMaximoNumeroEscuela = QueryOver.Of <Escuela>().SelectList(p => p.SelectMax(e => e.NumeroEscuela)); var escuelaConMaximoNumeroEscuela = Session.QueryOver <Escuela>().Where( Subqueries.WhereProperty <Escuela>(c => c.NumeroEscuela).Eq(criterioMaximoNumeroEscuela)). List(); return(escuelaConMaximoNumeroEscuela != null && escuelaConMaximoNumeroEscuela.Count > 0 ? escuelaConMaximoNumeroEscuela.First().NumeroEscuela : 0); }
/// <summary> /// 지정된 속성이 지정된 값과 같거나, 속성 값이 NULL인 경우 (예: Name=:Name OR Name IS NULL) /// </summary> public static QueryOver <TRoot, TSub> AddEqIncludeNull <TRoot, TSub>(this QueryOver <TRoot, TSub> queryOver, Expression <Func <TSub, object> > expr, object value) { var propertyName = RetrievePropertyName(expr); queryOver.UnderlyingCriteria.Add(Restrictions.Disjunction() .Add(Restrictions.Eq(propertyName, value)) .Add(Restrictions.IsNull(propertyName))); return(queryOver); }
public void test1() { Pet petAlias = null; var result = Session.QueryOver(() => petAlias) .WithSubquery.WhereExists( QueryOver.Of <Transporter>() .Where(x => x.Pet.Id == petAlias.Id) .Select(x => x.Id) ).List(); }
public IList <IncomingCallsAnalysisReportNode> GetLastOrderIdAndDeliveryDateByPhone( IUnitOfWork uow, IEnumerable <string> incomingCallsNumbers) { Phone phoneAlias = null; Counterparty counterpartyAlias = null; DeliveryPoint deliveryPointAlias = null; Order orderAlias = null; IncomingCallsAnalysisReportNode resultAlias = null; var query = uow.Session.QueryOver(() => phoneAlias) .Left.JoinAlias(() => phoneAlias.Counterparty, () => counterpartyAlias) .Left.JoinAlias(() => phoneAlias.DeliveryPoint, () => deliveryPointAlias) .Where(() => counterpartyAlias.Id != null || deliveryPointAlias.Id != null) .WhereRestrictionOn(() => phoneAlias.DigitsNumber).IsInG(incomingCallsNumbers); var lastOrderIdForCounterparty = QueryOver.Of(() => orderAlias) .Where(() => orderAlias.Client.Id == counterpartyAlias.Id) .Select(o => o.Id) .OrderBy(o => o.DeliveryDate).Desc .Take(1); var lastOrderIdForDeliveryPoint = QueryOver.Of(() => orderAlias) .Where(() => orderAlias.DeliveryPoint.Id == deliveryPointAlias.Id) .Select(o => o.Id) .OrderBy(o => o.DeliveryDate).Desc .Take(1); var lastOrderDeliveryDateForCounterparty = QueryOver.Of(() => orderAlias) .Where(() => orderAlias.Client.Id == counterpartyAlias.Id) .Select(o => o.DeliveryDate) .OrderBy(o => o.DeliveryDate).Desc .Take(1); var lastOrderDeliveryDateForDeliveryPoint = QueryOver.Of(() => orderAlias) .Where(() => orderAlias.DeliveryPoint.Id == deliveryPointAlias.Id) .Select(o => o.DeliveryDate) .OrderBy(o => o.DeliveryDate).Desc .Take(1); return(query.SelectList(list => list .Select(() => phoneAlias.DigitsNumber).WithAlias(() => resultAlias.PhoneDigitsNumber) .Select(() => counterpartyAlias.Id).WithAlias(() => resultAlias.CounterpartyId) .Select(() => deliveryPointAlias.Id).WithAlias(() => resultAlias.DeliveryPointId) .Select(Projections.Conditional( Restrictions.IsNull(Projections.Property(() => counterpartyAlias.Id)), Projections.SubQuery(lastOrderIdForDeliveryPoint), Projections.SubQuery(lastOrderIdForCounterparty))).WithAlias(() => resultAlias.LastOrderId) .Select(Projections.Conditional( Restrictions.IsNull(Projections.Property(() => counterpartyAlias.Id)), Projections.SubQuery(lastOrderDeliveryDateForDeliveryPoint), Projections.SubQuery(lastOrderDeliveryDateForCounterparty))).WithAlias(() => resultAlias.LastOrderDeliveryDate)) .TransformUsing(Transformers.AliasToBean <IncomingCallsAnalysisReportNode>()) .List <IncomingCallsAnalysisReportNode>()); }
public IQueryOver <ForecastMonth, ForecastMonth> Apply(IQueryOver <ForecastMonth, ForecastMonth> queryOver, ForecastMonth monthAlias, Trex.Server.Core.Model.Forecast.Forecast forecastAlias) { var forecastTypeCrit = QueryOver .Of <Trex.Server.Core.Model.Forecast.Forecast>() .Where(x => x.ForecastType.Id == _forecastTypeId) .And(x => x.ForecastMonth.Id == monthAlias.Id) .Select(x => x.Id) .Take(1); return(queryOver.Where(Subqueries.WhereExists(forecastTypeCrit))); }
public void Can_Get_Company_with_Identification_1() { QueryOver <CompanyIdentification, CompanyIdentification> detachedQuery = QueryOver.Of <CompanyIdentification>() .Where(ci => ci.Identification == "1") .Select(Projections.Id()); Company company = Repository.Get(qry => qry.WithSubquery.WhereExists(detachedQuery)); Assert.IsNotNull(company); Assert.IsFalse(NHibernateUtil.IsInitialized(company.Identifications)); }
public static IPagedList <T> PagedChildren <T>(this Webpage webpage, QueryOver <T> query = null, int pageNum = 1, int pageSize = 10) where T : Webpage { query = query ?? QueryOver.Of <T>() .Where(a => a.Parent == webpage && a.Published) .OrderBy(arg => arg.PublishOn) .Desc; return(MrCMSApplication.Get <ISession>().Paged(query, pageNum, pageSize)); }
public int GetUltimoNumeroMab() { //return (int) Session.CreateCriteria(typeof(Mab)).SetProjection( Projections.Max("Id") ).UniqueResult(); var criterioMaximoNumeroMab = QueryOver.Of <Mab>().SelectList(p => p.SelectMax(e => e.Id)); var mabConMaximoNumeroId = Session.QueryOver <Mab>().Where( Subqueries.WhereProperty <Mab>(c => c.Id).Eq(criterioMaximoNumeroMab)). List(); return(mabConMaximoNumeroId != null && mabConMaximoNumeroId.Count > 0 ? mabConMaximoNumeroId.First().Id + 1 : 1); }
public void QueryOverOf_AddIsOverlap_IsOverlap_HasRange() { var loaded = QueryOver.Of <User>() .AddIsOverlap(new TimeRange(DateTime.Now.AddHours(-1), DurationUtil.Hours(2)), u => u.ActivePeriod.Start, u => u.ActivePeriod.End) .GetExecutableQueryOver(UnitOfWork.CurrentSession); loaded.RowCount().Should().Be.GreaterThan(0); loaded.List().RunEach(log.Debug); }
protected override IQueryOver <IssuanceSheet> ItemsQuery(IUnitOfWork uow) { IssuanceSheetJournalNode resultAlias = null; IssuanceSheet issuanceSheetAlias = null; IssuanceSheetItem issuanceSheetItemAlias = null; Organization organizationAlias = null; Subdivision subdivisionAlias = null; EmployeeCard employeeCardAlias = null; var employeesSubquery = QueryOver.Of <IssuanceSheetItem>(() => issuanceSheetItemAlias) .Where(() => issuanceSheetItemAlias.IssuanceSheet.Id == issuanceSheetAlias.Id) .JoinQueryOver(x => x.Employee, () => employeeCardAlias) .Select(CustomProjections .GroupConcat(Projections .Property(() => employeeCardAlias.LastName), useDistinct: true, separator: ", ")); var query = uow.Session.QueryOver <IssuanceSheet>(() => issuanceSheetAlias); if (Filter.StartDate != null) { query.Where(x => x.Date >= Filter.StartDate); } if (Filter.EndDate != null) { query.Where(x => x.Date <= Filter.EndDate); } return(query .Where(GetSearchCriterion( () => issuanceSheetAlias.Id, () => issuanceSheetAlias.Expense.Id, () => issuanceSheetAlias.CollectiveExpense.Id, () => organizationAlias.Name, () => subdivisionAlias.Name, () => subdivisionAlias.Code )) .Left.JoinAlias(s => s.Organization, () => organizationAlias) .Left.JoinAlias(s => s.Subdivision, () => subdivisionAlias) .SelectList((list) => list .Select(x => x.Id).WithAlias(() => resultAlias.Id) .Select(x => x.Date).WithAlias(() => resultAlias.Date) .Select(() => organizationAlias.Name).WithAlias(() => resultAlias.Organigation) .Select(() => subdivisionAlias.Name).WithAlias(() => resultAlias.Subdivision) .Select(() => subdivisionAlias.Code).WithAlias(() => resultAlias.SubdivisionCode) .Select(x => x.Expense.Id).WithAlias(() => resultAlias.DocExpenseId) .Select(x => x.CollectiveExpense.Id).WithAlias(() => resultAlias.DocCollectiveExpenseId) .SelectSubQuery(employeesSubquery).WithAlias(() => resultAlias.Employees) ) .OrderBy(() => issuanceSheetAlias.Date).Desc .ThenBy(() => issuanceSheetAlias.Id).Desc .TransformUsing(Transformers.AliasToBean <IssuanceSheetJournalNode>())); }
public QueryOver <Event> GetQuery() { var myFriends = QueryOver.Of <Connection>() .Where(c => c.MyId == myAccount.FacebookLogon.FacebookId) .Select(c => c.FriendId); var activityBelongToFriend = QueryOver.Of <Event>() .JoinQueryOver <Account>(a => a.Organizers) .WithSubquery.WhereProperty(c => c.FacebookLogon.FacebookId).In(myFriends); return(activityBelongToFriend); }
public IList <Site> GetPendingQueuedTaskSites() { using (new SiteFilterDisabler(_session)) { Site siteAlias = null; return(_session.QueryOver(() => siteAlias) .WithSubquery.WhereExists(QueryOver.Of <QueuedTask>() .Where(task => task.Status == TaskExecutionStatus.Pending && task.Site.Id == siteAlias.Id) .Select(task => task.Id)) .List()); } }
public void ReportAll_Matching_QueryOver_With_Order() { var eqName = QueryOver.Of <Parent>().AddInsensitiveLike(p => p.Name, "Paren", MatchMode.Start); ICollection <ParentDTO> dtos = Repository <Parent> .ReportAll <ParentDTO>(eqName, ProjectByNameAndAge, new NHOrder <Parent>(p => p.Name, false)); Assert.AreEqual(parentsInDB.Count, dtos.Count); AssertDtosSortedByName(dtos, "Desc"); }
public void QueryOverOf_AddIsOverlap_IsEndOpenRange() { var loaded = QueryOver.Of <User>() .AddIsOverlap(new TimeRange(DateTime.Today, null), u => u.ActivePeriod.Start, u => u.ActivePeriod.End) .GetExecutableQueryOver(UnitOfWork.CurrentSession); loaded.RowCount().Should().Be.GreaterThan(0); loaded.List().RunEach(log.Debug); }
internal void Run() { using (Session.BeginTransaction()) { Console.WriteLine("List all..."); var items = Session.CreateCriteria(typeof(DataItem)) .List <DataItem>(); foreach (var item in items) { Write(item); } Console.WriteLine("Fetch and filter using QueryOver..."); DataItem dataItemAlias = null; var c = QueryOver.Of <DataItem>(() => dataItemAlias); c.WhereRestrictionOn(x => x.Source).IsInsensitiveLike("A"); DataItem maxSendDateTimeAlias = null; /* var subQuery = QueryOver.Of<DataItem>(() => maxSendDateTimeAlias) * .Select(Projections.ProjectionList() * .Add(Projections.Max(() => maxSendDateTimeAlias.SendDateTime)) * .Add(Projections.Group(() => maxSendDateTimeAlias.Target))) * .Where(() => dataItemAlias.Source == maxSendDateTimeAlias.Source); */ var subQuery = QueryOver.Of <DataItem>() .Select( Projections.ProjectionList() .Add(Projections.SqlGroupProjection("max(SendDateTime) as maxSendDateTimeAlias", "Target", new string[] { "maxAlias" }, new IType[] { NHibernate.NHibernateUtil.Int32 }))); c.WithSubquery.WhereProperty(p => p.SendDateTime).In(subQuery); var result = c.GetExecutableQueryOver(Session).List <DataItem>(); foreach (var item in result) { Write(item); } } Console.WriteLine("Press D to empty data or other to close"); var key = Console.ReadKey(); if (key.Key == ConsoleKey.D) { Session.CreateQuery("delete from DataItem").ExecuteUpdate(); } }
public static QueryOver <Warehouse> GetRestrictedWarehouseQuery(params WarehousePermissions[] permissions) { var query = QueryOver.Of <Warehouse>().WhereNot(w => w.IsArchive); var disjunction = new Disjunction(); foreach (var p in permissions) { disjunction.Add <Warehouse>(w => w.Id.IsIn(CurrentPermissions.Warehouse.Allowed(p).Select(x => x.Id).ToArray())); } return(query.Where(disjunction)); }
protected void OnBtnAddGeographicGroupClicked(object sender, EventArgs e) { var selectGeographicGroups = new OrmReference( QueryOver.Of <GeographicGroup>().Where(gg => gg.Id != ViewModel.EastGeographicGroupId)) { Mode = OrmReferenceMode.MultiSelect }; selectGeographicGroups.ObjectSelected += SelectGeographicGroups_ObjectSelected; Tab.TabParent.AddSlaveTab(Tab, selectGeographicGroups); }
/// <summary> /// The get shared crosswords by user id. /// </summary> /// <param name="userId"> /// The user id. /// </param> /// <returns> /// The <see cref="IEnumerable{CrosswordDTO}"/>. /// </returns> public IEnumerable <CrosswordDTO> GetSharedCrosswordsByUserId(int userId) { QueryOver <User, User> subQuery = QueryOver.Of <User>().Where(x => x.Id == userId).Select(res => res.Company.Id); AppletItem ai = null; SubModuleItem smi = null; SubModuleCategory smc = null; User u = null; User u2 = null; CrosswordDTO dto = null; QueryOver <AppletItem, User> queryOver = new DefaultQueryOver <AppletItem, int>().GetQueryOver(() => ai) .JoinQueryOver(x => x.SubModuleItem, () => smi, JoinType.InnerJoin) .Where(() => smi.IsActive == true && smi.IsShared == true) .JoinQueryOver(() => smi.SubModuleCategory, () => smc, JoinType.InnerJoin) .Where(() => smc.IsActive == true) .JoinQueryOver(() => smc.User, () => u, JoinType.InnerJoin) .JoinQueryOver(() => smi.CreatedBy, () => u2, JoinType.InnerJoin) .Where(() => u2.Id != userId && (int)u2.Status == 1) .WithSubquery.WhereProperty(() => u2.Company.Id) .In(subQuery) .SelectList( res => res.Select(() => ai.AppletName) .WithAlias(() => dto.appletName) .Select(() => ai.Id) .WithAlias(() => dto.appletItemId) .Select(() => u.LastName) .WithAlias(() => dto.lastName) .Select(() => u.FirstName) .WithAlias(() => dto.firstName) .Select(() => u.Id) .WithAlias(() => dto.userId) .Select(() => u2.LastName) .WithAlias(() => dto.createdByLastName) .Select(() => u2.FirstName) .WithAlias(() => dto.createdByName) .Select(() => smi.CreatedBy.Id) .WithAlias(() => dto.createdBy) .Select(() => smi.DateModified) .WithAlias(() => dto.dateModifiedData) .Select(() => smi.Id) .WithAlias(() => dto.subModuleItemId) .Select(() => smc.CategoryName) .WithAlias(() => dto.categoryName) .Select(() => smc.Id) .WithAlias(() => dto.subModuleCategoryId)) .TransformUsing(Transformers.AliasToBean <CrosswordDTO>()); List <CrosswordDTO> result = this.Repository.FindAll <CrosswordDTO>(queryOver).ToList(); return(result); }
public static IPagedList <T> Paged <T>(this ISession session, QueryOver <T> query, int pageNumber, int?pageSize = null) where T : SystemEntity { int size = pageSize ?? MrCMSApplication.Get <SiteSettings>().DefaultPageSize; IEnumerable <T> values = query.GetExecutableQueryOver(session).Skip((pageNumber - 1) * size).Take(size).Cacheable().List <T>(); var rowCount = query.GetExecutableQueryOver(session).ToRowCountQuery().SingleOrDefault <int>(); return(new StaticPagedList <T>(values, pageNumber, size, rowCount)); }
public QueryOver <Connection> GetQuery() { var myFriends = QueryOver.Of <Connection>() .Where(c => c.MyId == myAccount.FacebookLogon.FacebookId) .Select(c => c.FriendId); var isFriendsOfFriends = QueryOver.Of <Connection>() .Where(c => c.MyId == friendAccount.FacebookLogon.FacebookId) .WithSubquery.WhereProperty(c => c.FriendId).In(myFriends); return(isFriendsOfFriends); }
/// <summary> /// The get one by SMI id. /// </summary> /// <param name="userId"> /// The user id. /// </param> /// <returns> /// The <see cref="IEnumerable{SNProfile}"/>. /// </returns> public IEnumerable <SNProfileExtraDTO> GetAllSharedByUserId(int userId) { SNProfile profile = null; SubModuleItem smi = null; SubModuleCategory smc = null; User u = null; User u2 = null; SNProfileExtraFromStoredProcedureDTO dto = null; const UserStatus ActiveStatus = UserStatus.Active; var user = this.userModel.GetOneById(userId).Value; var companyId = user.Company.Id; return (this.Repository.FindAll <SNProfileExtraFromStoredProcedureDTO>( QueryOver.Of(() => profile) .JoinAlias(x => x.SubModuleItem, () => smi) .Where(() => smi.IsActive == true && smi.IsShared == true) .JoinAlias(() => smi.SubModuleCategory, () => smc) .Where(() => smc.IsActive == true) .JoinAlias(() => smc.User, () => u) .JoinAlias(() => smi.CreatedBy, () => u2) .Where(() => u2.Id != userId && u2.Status == ActiveStatus && u2.Company.Id == companyId) .SelectList( list => list.Select(() => smc.Id) .WithAlias(() => dto.subModuleCategoryId) .Select(() => smc.CategoryName) .WithAlias(() => dto.categoryName) .Select(() => smi.Id) .WithAlias(() => dto.subModuleItemId) .Select(() => smi.DateModified) .WithAlias(() => dto.dateModified) .Select(() => u2.Id) .WithAlias(() => dto.createdBy) .Select(() => u2.FirstName) .WithAlias(() => dto.createdByFirstName) .Select(() => u2.LastName) .WithAlias(() => dto.createdByLastName) .Select(() => u.Id) .WithAlias(() => dto.userId) .Select(() => u.FirstName) .WithAlias(() => dto.firstName) .Select(() => u.LastName) .WithAlias(() => dto.lastName) .Select(() => profile.Id) .WithAlias(() => dto.snProfileId) .Select(() => profile.ProfileName) .WithAlias(() => dto.profileName)) .TransformUsing(Transformers.AliasToBean <SNProfileExtraFromStoredProcedureDTO>())) .ToList() .Select(x => new SNProfileExtraDTO(x))); }
public void CloneQueryOver() { QueryOver <Person> expected = QueryOver.Of <Person>() .Where(p => p.Name == "test") .Select(p => p.Name); QueryOver <Person> actual = expected.Clone(); Assert.That(actual, Is.Not.SameAs(expected)); Assert.That(actual.UnderlyingCriteria, Is.Not.SameAs(expected.UnderlyingCriteria)); AssertCriteriaAreEqual(expected.UnderlyingCriteria, actual.UnderlyingCriteria); }
public void DetachedQueryOver() { DetachedCriteria expected = DetachedCriteria.For <Person>("personAlias") .Add(Restrictions.Eq("personAlias.Name", "test name")); Person personAlias = null; QueryOver <Person> actual = QueryOver.Of <Person>(() => personAlias) .Where(() => personAlias.Name == "test name"); AssertCriteriaAreEqual(expected, actual); }
private AbstractCriterion CreatePropertyCriterion <U>(Func <string, DetachedCriteria, AbstractCriterion> propertyFactoryMethod, Func <object, DetachedCriteria, AbstractCriterion> valueFactoryMethod, QueryOver <U> detachedCriteria) { if (propertyName != null) { return(propertyFactoryMethod(propertyName, detachedCriteria.DetachedCriteria)); } else { return(valueFactoryMethod(value, detachedCriteria.DetachedCriteria)); } }
/// <summary> /// Entity의 Name 속성 값이 <paramref name="name"/>와 일치하는 entity 들을 조회한다. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="name"></param> /// <returns></returns> public static IList <T> FindAllByName <T>(string name) where T : class, INamedEntity { if (IsDebugEnabled) { log.Debug("특정 Name 값을 가지는 모든 엔티티를 로드합니다... entity=[{0}], Name=[{1}]", typeof(T).Name, name); } return (QueryOver.Of <T>() .AddEqOrNull(entity => entity.Name, name) .GetExecutableQueryOver(UnitOfWork.CurrentSession) .List()); }
public void DetachedQuery_SimpleCriterion() { using (ISession s = OpenSession()) using (ITransaction t = s.BeginTransaction()) { s.Save(new Person() { Name = "test person 1", Age = 20 }); t.Commit(); } using (ISession s = OpenSession()) { QueryOver<Person> personQuery = new QueryOver<Person>() .Where(p => p.Name == "test person 1"); IList<Person> actual = personQuery.GetExecutableQueryOver(s) .List(); Assert.That(actual[0].Age, Is.EqualTo(20)); } }
public static IList<Event> GetQueryResult(int skip, int maxRow, QueryOver<Event> query) { using (ISession session = NHibernateHelper.OpenSession()) { return query.GetExecutableQueryOver(session).Skip(skip).Take(maxRow).List(); } }