Questions tagged [nhibernate-queryover]

1

votes
0

answer
57

Views

NHibernate JoinAlias avoid select of nested items

I have a parent children relation, and I need to filter parent and children i some way, here a snippet example: Child childAlias = null; session.QueryOver() .JoinAlias(i => i.Children, () => childAlias) .Where(() => childAlias.Name == 'Child01') .And(u => u.Id == 'a4ccba801f1844b4921e17edb9ffa13f')...
Luca Mazzanti
1

votes
0

answer
52

Views

Returning ROW_NUMBER() from Nhibernate QueryOver

I've been feverishly trying to figure out how to return the ROW_NUMBER() (not the row count) from a NHibernate QueryOver. This has now become equal parts a learning exercise, so i understand that there are easy alternatives like returning the whole set and iterating through it. But lets stick with...
Juls
1

votes
2

answer
64

Views

NHibernate query over projection

I have two entities A and B where A has one-to-many relationship with B. I would like to create an NHibernate query that fetches all A entities with all the B records, where: the A entity is active the fetched B entities are within a date range (I have 2 c# DateTime objects). entity A +----+-------...
LIvanov
1

votes
1

answer
2k

Views

Select records having max value in column using NHibernate QueryOver

Can I do this using QueryOver in NHibernate? SELECT * FROM TABLE_X T1 WHERE T1.COL1 = (SELECT MAX(COL1) FROM TABLE_X T2 WHERE T1.NAME = T2.NAME)
H77
1

votes
1

answer
895

Views

Using NHibernate QueryOver with a complex scenario

I´m trying to use QueryOver in that scenario : public class Class1 { public virtual string Name { get; set; } public virtual string Descripton { get; set; } public virtual Class2 { get; set; } public virtual IList ListClass3{ get; set; } ... //SEVERAL OTHERS LISTS, PROPERTIES } public class Class2...
Paul
1

votes
2

answer
456

Views

How to batch fetch child-properites from a list of items?

I have a search-method which returns multiple items, each with several child-properties with references to other tables. For the child-property that is a collection everything works as I want it to but how can I do the same for the one-to-one children? Here is some stubs and some of the code I tried...
Fredrik C
1

votes
1

answer
573

Views

NHibernate QueryOver Where Exists

CUSTOMER, COMPANY and a relational table CUSTOMER_COMPANY which keeps relation between companies and customers. I have a list of emails List emailList I want to search for customers which belongs to a specific company and his/her email(which is a field) is in this emailList. How can I do with Quer...
1

votes
1

answer
245

Views

NHibernate: Reverse Exists Criteria

I'm querying Foo. Foo doesn't have an IList property (unfortunately). FooBar has a Foo property (but not a Bar), Bar has an IList. I need all the Foos where exists a FooBar which has a corresponding Bar with that Bar's Date field equal to today. I'm not really a pro with Criteria API, but it's not m...
TDaver
1

votes
1

answer
171

Views

Can you project multiple aggregates from a single QueryOver

I can create a single aggregate projection on a collection of entities example Return the number of shops that are active But is there a way to project the number of a bunch of different summations in the same query over? example number of shops that are active? Number of shops with active products?...
pghtech
1

votes
1

answer
1.2k

Views

C# NHibernate dynamically add Where clauses (jqgrid)

Is it possible to add where clauses dynamically to an NHibernate Query? I have a collection of Clauses I need to Loop through and add a Where clause if required - i.e. if the user has entered multiple search criteria. I Can write single queries, no problem, like this: get All Names beginning with...
Andrew Humphries
1

votes
1

answer
1.3k

Views

Nhibernate: No persister for: System.Collections.Generic.List

Any ideas why I might be getting 'No persister for: System.Collections.Generic.List' exception when executing the query below? var subs = new List(); var subsections = Session.QueryOver() .WhereRestrictionOn(s => s.Id) .IsInG(subsectionIds) .List(); Location foreignExpertLocation = null; var result...
Chirdeep Tomar
1

votes
1

answer
128

Views

Why is everything being eagerly loaded?

I'm trying to get to grips with QueryOver, and I was expecting this to return me a Summary item with its ReportRows collection eagerly loaded. Update The first block of code wasn't in my original question but it was the cause of my problem - thanks to dotjoe for the answer // some code to create a S...
Richard
1

votes
1

answer
246

Views

query over one type in different entities

Here is a small extract of my domain model: public class Chain { public IList Products { get; set; } } public class Store { public Chain Chain { get; set; } public IList Products { get; set; } } Now I need to create a query over Product in Store and the associated Chain. The question is how can I e...
core
1

votes
1

answer
1.9k

Views

QueryOver child collection from parent

I have this 2 objects: public class Parent { public virtual int Poid { get; set; } public virtual IEnumerable Child { get; set; } } public class Child { public virtual int Poid { get; set; } public virtual string Name {get; set;} } I want to use NHibernet QueryOver API to get a child based on th...
Diego
1

votes
1

answer
2.1k

Views

Working around Duplicate association path bug in Nhibernate with Query Over

I've got a bit of code that tries to access same association path twice and they're really same aliases but because I'm using query objects, I have them in two different places and I am not really sure how to get the alias. May be some code can clear the confusion: var privateBlogQuery = new BlogQu...
LocustHorde
1

votes
2

answer
612

Views

Exception in NHibernate query when use Contains

I have the following classes: class Operation { User User_AssignedTo; ResourceGroup ResourceGroup; } class ResourceGroup { List UsersCollection; } And I have method. It takes user and returns operations. Something like that: ResourceGroup resourceGroup = null; query = conn.Session.QueryOver() .Joi...
Max
1

votes
1

answer
4.9k

Views

NHibernate JoinQueryOver

Calling all NHibernate gurus out there! If any one of you brainy folks could help me with the following conundrum I'd be most grateful: I have some entities that describe RSS feeds from various sources that are grouped together in an entity called FeedList. I am trying to select only the distinct So...
Chris Birch
1

votes
1

answer
2.9k

Views

NHibernate projection: How to create AliasToBean projection?

I am trying to convert this inefficient query into one that projects into a dto. Original query looks like this: var flatFeePolicies = _session.QueryOver(() => flatChargeAccessFeeAlias) .JoinAlias(x => x.AgreementAccessFee, () => agreementAccessFeeAlias) .JoinQueryOver(x => x.ClientPolicy, () => cli...
epitka
1

votes
1

answer
1.8k

Views

Session.QueryOver: What does error : variable 'rg' of type ReportingGroup referenced from scope , but it is not defined" mean?

This is the query: var reportingGroupYears = _session.QueryOver() .Where(x => x.Number == request.ReportingGroupNumber) .Select(rg=> rg.Year.ToString()) .List(); I don't understand what is wrong with it. Defining 'rg' as string is not allowed either, as it give message that it would give rg a differ...
epitka
1

votes
1

answer
895

Views

When does NHibernate JoinQueryOver load full collection?

I've got a model where a Person has a lazy-loaded collection of Registrations. My NHibernate 3.3.3 query uses JoinQueryOver across that relation and some more: var reg = Session.QueryOver() .Where(p => p.ID == pid) .JoinQueryOver(p => p.Registrations) .Where(r => r.IsDropped == false) .JoinQueryOve...
Carl Raymond
1

votes
1

answer
251

Views

NHibernate QueryOver with leftjoins

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:...
Martin Horvath
1

votes
2

answer
523

Views

Add restriction on discriminator (class type) to select subset of classes in fluent nhibernate

I'm using fluent nhibernate with Discriminator for subclasses. (very similar to this question) For example, assume I have classes Cat, Dog, and Racoon that extend abstract class Animal. I want to be able to select both Cat, And Dog but leave out Racoon. So return _db.CreateCriteria.List(); will not...
LocustHorde
1

votes
1

answer
1.1k

Views

Fluent NHibernate Querying: Check for nullable column values

I have the following problem: I have a nullable column in my database table. I want to be able to add a filter for it in my Where clause. However, when the column is in fact null, I get an error: 'Object reference not set to an instance of an object.' public class MyClass { public virtual float? Id...
user1211204
1

votes
1

answer
99

Views

NHibernate fully populate a partially loaded collection

I have a schema with Project objects. Each Project has an owner, and an additional collection of SharePermission objects detailing other users that can also access the Project. SharePermissions point to a more detailed user object of type IdentityUser In this case, I load an IEnumerable of Projects...
AndySavage
1

votes
1

answer
2.3k

Views

Return List of MAX Value after group QueryOver Nhibernate

Please help, Can I do this in query over nhibernate? select max(Id) from transTable group by PortfolioId. I've tried this. var subquery = QueryOver.Of(() => q) .SelectList(list => list.SelectGroup(() => q.PortfolioId)) .Where(Restrictions.EqProperty( Projections.Property(() => p.Id), Projections.Max...
hutagaol junedi
1

votes
1

answer
648

Views

Fluent NHibernate QueryOver: avoid orderby null reference table

I'm using Fluent NHibernate to map a fairly simple database. I'm having a problem with the following situation. Let's say my class looks like so ClassA ------- ... string A_Name; ClassB InnerObject; innerObjectAlias.B_Name).Asc(); } Any help would be greatly appreciated.
user1211204
1

votes
1

answer
224

Views

nhibernate group by and join query

I need nhiberante query (not HQL) equivalent following SQL: SELECT ur.* FROM (SELECT MAX(requestTime) rt, macAddress ma FROM UpdateRequests GROUP BY macAddress) mur JOIN dbo.UpdateRequests ur ON mur.ma = ur.macAddress AND mur.rt = ur.requestTime I had no luck with other similar examples on stackover...
alloha
1

votes
1

answer
583

Views

Query over Max with function

I am try to construct this query in nHibernate: SELECT max(split_part(person.Name,'-',2)) FROM data.person How can I make this using projections ? I have this at the moment : session.QueryOver() .Select(Projections.Max(x=>Projections.SqlFunction('split_part', NHibernateUtil.String, Projections.Pr...
user3511244
1

votes
1

answer
810

Views

NHibernate - How to QueryOver in joined table with restrictions

I am stuck with a SQL query (using NHibernate 4). I have 2 tables (Client and Technology) with many-to-many relationship so I created a junction table called ClientTechnology. I am trying to retrieve all the Technologies available (that are non-custom) PLUS all the Technologies available (that are c...
iberodev
1

votes
1

answer
2.5k

Views

How to join Two tables of two non relashinship defined columns using Nhibernate QueryOver

Using NHibernate QueryOver, I want to join two tables using two columns which are not defined in the mapping as a relationship. E.g. This is not my exact scenario but this can explain that Tables: Employee(Id, Name, DepartmentId, SomeCode,Address) Department (Id, Name, ,Code) Select SELECT * FROM E...
Niruka
1

votes
1

answer
866

Views

QueryOver ProjectionList with different root entity types

I'm having issues trying to reuse ProjectionLists in NHibernate QueryOvers. I can't work out how to reuse things for different root entities. Object model is roughly represented as: Breakfast one to many Pastry many to zero-or-one Coffee The two separate queries are roughly: session.QueryOver() .Whe...
Duncan Matheson
1

votes
1

answer
191

Views

How to limit rows count only of left part of join with QueryOver?

Take() limits the total rows count of the whole query result but I need to limit only rows of the left side of the join to retrieve 50 users and all their characters: session.QueryOver(() => userAlias) .Where(...) //.Take(50) - can't do this! .JoinAlias(x => x.Characters, () => characterAlias, Join...
Vlad
1

votes
1

answer
463

Views

NHibernate: ProjectionList: Can we create dynamic projectionlist for Orderby

I am working on a query in NHibernate in which user could provide a sorting order for some selected fields. I need to do a OrderBy() in QueryOver with the names of field names in entities, but when using projection list I am getting like this. SELECT this_.Number as y0_, scc3_.Code as y1_, FROM some...
Builder
1

votes
1

answer
522

Views

NHibernate - QueryOver criteria appearing in Where instead in Having clause, error

I have a problem in QueryOver where using Group by and have some criteria in where clause. Want to move some criteria with SUM() values in Having clause but every time it appears in Where clause and result in error. **Error** ='*An aggregate may not appear in the WHERE clause unless it is in a subqu...
Builder
1

votes
1

answer
215

Views

Nhibernate Query Over exception on join with invalid value

-- tbl_Region-- ID DisplayName Description IsUsingLineNumbers WaitPeriod FK_StateId 1 UPS Upstate 0 10 1 2 DWN Downstate 1 20 1 3 OK Oklahoma 1 15 2 -...
sunil singh
1

votes
1

answer
300

Views

Table-per-subclass fluent nhibernate not working

I have the following classes defined: And these tables in my database: My fluent NHibernate mappings are: public class BusinessUnitMap : ClassMap { public BusinessUnitMap() { Table('BusinessUnits'); Id(x => x.Id); Map(x => x.Code); Map(x => x.Name); Map(x => x.ParentId); Map(x => x.Type).Column('Typ...
SonOfPirate
1

votes
1

answer
620

Views

How to eager load objects in a list/collection?

I have the following query: ObjectB objectBAlias = null; ObjectC objectCAlias = null; var query = session.QueryOver(); var results = query .JoinAlias(x => x.listOfBs, () => objectBAlias) .JoinAlias(x => objectBAlias.ObjectC, () => objectCAlias) .TransformUsing(new DistinctRootEntityResultTransformer...
dmarsi
1

votes
1

answer
445

Views

QueryOver With Custom Projection and Query Parameter

I've defined a query in a class with a property, but am trying to build a fairly complex query using the property and have run into NHibernate telling me that it could not resolve property: DueDate. My Query class looks like this: public class SomeQuery { public DateTime DueDate { get; private set;...
scott-pascoe
1

votes
1

answer
532

Views

Multiple columns query - Nhibernate using QueryOver

I'm using NHibernate with oracle db and I want to make a query that selects many columns. For example, lets say I have a table named Soldiers with the following columns : Id, first name and last name. I want to select and return the first name and last name of all the soldiers, so in sql it will be...
Pachu
1

votes
1

answer
152

Views

Filtering Sub Collections with QueryOver

I would like to write a query that filters a child collection of the base type in my QueryOver. For example... class Person{ List contacts; } class Contact{ string PhoneNumber; bool isHome; } Then QueryOver.Of() .JoinQueryOver(p => p.Contact) .Where(c => c.isHome); Which I want to return all the peo...
Callback Kid

View additional questions