queryover

NHibernate: Select one to Many Left Join - Take X latest from Parent

人盡茶涼 提交于 2019-12-17 21:59:59
问题 I have the following objects: Parent public virtual Guid Id { get; set; } public virtual DateTime TimeStamp { get; set; } public virtual IList<Child> Childs { get; set; } Child public virtual Guid Id { get; set; } public virtual string Name { get; set; } I use Fluent to Map One To Many as follows: .Override<Parent>(obj =>obj.HasMany(x => x.Childs) .Cascade.All() .Not.Inverse() .Not.KeyNullable() .Not.KeyUpdate()) I need to get up to all Parent with Childs between dates order by TimeStamp. I

NHibernate QueryOver to join unrelated entities

无人久伴 提交于 2019-12-17 19:28:42
问题 I have the following query working which gets the results I want: int associatedId = 123; MyObject alias = null; var subQuery = QueryOver.Of<DatabaseView>() .Where(view => view.AssociatedId == associatedId) .And(view => view.ObjectId == alias.ObjectId) .Select(view => view.ObjectId); var results = session.QueryOver<MyObject>(() => alias) .WithSubquery.WhereExists(subQuery) .List(); DatabaseView has been mapped as an actual NHibernate entity (so I can use it with QueryOver), but it is not

NHibernate QueryOver extensibility

☆樱花仙子☆ 提交于 2019-12-13 19:21:04
问题 Is it possible to extend QueryOver API by somehow? What I want to add is the fol var criteria = QueryOver.Of<InternalAssessor>() .WhereRestrictionOn(x => x.Sector).HasAtLeastOneFlagSet((int)sector) Where sector is bit flag enum. We had such criterion for ICriteria API and I can do .Where(BitwiseRestrictions.AtLeastOneFlagSet("Sector", (int)sector)) But want to have strongly typed way of doing it. Are there any examples of extending QueryOver? 回答1: There is, pretty straightforward way, how to

NHibernate - QueryOver Child rows as comma separated values

☆樱花仙子☆ 提交于 2019-12-13 15:53:06
问题 I have to write a query where for each vendor I have to read vendor's contact numbers from VendorContact but instead in rows, one row for each unique vendor and one columns for each phone number as comma separated string in main result. This can be done easily in plain SQL but I have to do it in QueryOver . I cannot declare variables in QueryOver SQL . var vendorvar = Session.QueryOver<Vendor>(() => V) .Left.JoinQueryOver(() => v.ContactNumbers, () => VendorContact) .SelectList(list => lst

How to make Nhibernate Case sensitive query using QueryOver?

别说谁变了你拦得住时间么 提交于 2019-12-13 04:28:34
问题 I have a simple database with users table, it have simple admin user with UserName= "Admin" Password="admin" I am using NHibernate to query over this table to login form. Suppose the login form inserted UserName="ADMIN" and password="ADMIN" both in upper case. The system should not allow login. However when I use the query like this using (var session = NhibernateHelper.OpenSession()) { return new List<User> (session.QueryOver<User>() .Where(u => u.UserName == userName) .And(u => u.Password =

Nhibernate return a specific type of union subclass in a QueryOver with join

喜欢而已 提交于 2019-12-13 04:27:40
问题 This is my current nhibenate query MappedHSPItemDto itemDtoAlias = null; TItem itemAlias = default(TItem); return Session.QueryOver<TMapItem>() .JoinAlias(x => x.Item, () => itemAlias, JoinType.InnerJoin) .Where(x => x.HealthServiceProvider == hsp) .SelectList(list => list .Select(x => x.Id).WithAlias(() => itemDtoAlias.Id) .Select(x => x.Version).WithAlias(() => itemDtoAlias.Version) .Select(x => x.HSPItemCode).WithAlias(() => itemDtoAlias.HSPItemCode) .Select(x => x.HSPItemName).WithAlias((

NHibernate QueryOver with leftjoins

纵然是瞬间 提交于 2019-12-13 00:36:30
问题 This thing is keeping me busy for days and I hope someone of the NHibernate gurus can help me out. I've got a query set up which is working in SQL Server and I want to get the same in NHibernate. But all my tries (did a lot of googeling and browsing in stackoverflow) failed so far. Here's the query: Select j.id, j.title, j.company, jt.name as category, loc.city, je.is_assigned, FROM job j LEFT JOIN location loc ON loc.id = j.location LEFT JOIN job_tag jt ON jt.job = j.id and jt.name in

NHibernate QueryOver with sub-query and alias

白昼怎懂夜的黑 提交于 2019-12-12 09:44:07
问题 I'm struggling to convert the following (simplified) HQL to QueryOver: select subscription from Subscription as subscription where not exists ( from Shipment as shipment where shipment.Subscription = subscription and (shipment.DeliveryDate = :deliveryDate) ) I've come this far: Subscription subscription = null; Session.QueryOver(() => subscription) .Where(Subqueries.NotExists(QueryOver.Of<Shipment>() .Where(shipment => shipment.Subscription == subscription) .And(shipment=> shipment

Where clause not working with parantheses

▼魔方 西西 提交于 2019-12-12 02:27:09
问题 Suppose the following Query using a NH 3.4 and RepositoryPattern var list = _repository .QueryOver() .Where(x => (x.Age > 20)) // notice the parantheses .Future() .ToList(); Whith these parantheses added the NH is failing to work, and causes a SO exception. If replacing .Where(x => (x.Age > 20)) with .Where(x => x.Age > 20) it works as expected. Any clues on why it doesn't work with extra parantheses? Note This is a simplified scenario from the bigger picture. In production i'm passing that

Nhibernate queryover matching two IEnumerable

微笑、不失礼 提交于 2019-12-12 02:19:12
问题 i have this domain objects: public class Societa : EquatableObject<Societa> { public virtual int IdSocieta { get; set; } public virtual string NomeSocieta { get; set; } } public class Attivita { public virtual int IdAttivita { get; set; } public virtual IEnumerable<ProcessoEsaminato> Processi } public class ProcessoEsaminato { public virtual ProcessoSocieta ProcessoCoperto { get; set; } public virtual int Anno { get; set; } } public class ProcessoSocieta { public override int Id { get; set; }