linq-to-nhibernate

Problem with eager load polymorphic associations using Linq and NHibernate

Is it possible to eagerly load polymorphic association using Linq and NH? For example: Company is base class, Department is inherited from Company, and Company has association Employees to the User (one-to-many) and also association to the Country (many-to-one). Here is mapping part related to inherited class (without User and Country c...

SQL Group By and Join

I feel totally stupid. I'm rusty with my sql. I have two tables, Message and MessageThread. Each message belongs to one MessageThread using ParentTHreadID as a Foreign Key. You probably can see where this is going. Well, I want to do something like this. I want to get columns from both tables, messages and threads, but where the mes...

How to use PredicateBuilder with nested OR conditionals in Linq

I've been very happily using PredicateBuilder but until now have only used it for queries with only either concatenated AND statements or OR statements. Now for the first time I need a pair of OR statements nested along with a some AND statements like this: select x from Table1 where a = 1 AND b = 2 AND (z = 1 OR y = 2) Using the docu...

Linq to NHibernate - How to return a parent object with only certain child objects included

Given a simplified model like the following: public class Enquiry { public virtual DateTime Created { get; set; } public virtual Sender Sender { get; set; } } public class Sender { public virtual IList<Enquiry> Enquiries { get; set; } } How can you construct a Linq to Nhibernate query such that it gives you back a list of...

Nhibernate linq group by duplicate fields

Hello, I have a simple query like: from e in endContratoRepository.GetAll() where e.Contrato.idContrato == contrato.idContrato && e.Volume.idVolume == 1 && group e by new { e.dpto.idDepartamento, e.centroCusto.idCentro...

NHibernate with or without Repository

There are several similar questions on this matter, by I still haven't found enough reasons to decide which way to go. The real question is, is it reasonable to abstract the NHibernate using a Repository pattern, or not? It seems that the only reason behind abstracting it is to leave yourself an option to replace NHibernate with a diff...

Linq to NHibernate using Queryable.Where predicate

I am querying an SQLite database using LINQ to NHibernate. Person is an entity containing an Id and a Name: public class Person { public Guid Id { get; private set; } public string Name { get; private set; } } Let's say my db table contains a single person whose name is "John". This test works as expected: var query = from ...

Many-To-Many Query with Linq-To-NHibernate

Ok guys (and gals), this one has been driving me nuts all night and I'm turning to your collective wisdom for help. I'm using Fluent Nhibernate and Linq-To-NHibernate as my data access story and I have the following simplified DB structure: CREATE TABLE [dbo].[Classes]( [Id] [bigint] IDENTITY(1,1) NOT NULL, [Name] [nvarchar](100) NOT...

Where to put NHibernate query logic?

I am trying to set up proper domain architecture using Fluent NHibernate and Linq to NHibernate. I have my controllers calling my Repository classes, which do the NHibernate thang under the hood and pass back ICollections of data. This seems to work well because it abstracts the data access and keeps the NHibernate functionality in the...

Castle ActiveRecord / NHibernate Linq Querys with ValueTypes

Given the following code for our Active Record Entites and ValueTypes Linq is not working for us. [ActiveRecord("Person")] public class PersonEntity : ActiveRecordLinqBase<PersonEntity> { string _name; [Property("Name", Length = 20, ColumnType = "string", Access = PropertyAccess.FieldCamelcaseUnderscore)] public Name Name ...

Where is the new NHibernate Core Linq?

I'm running NHibernate 2.1.2.4000 but there's no Query() method off my session... Which version of NHibernate introduces linq into the core? I'm still running on the old Contrib Linq. I've just upgraded to the latest stable release of Sharp Architecture which makes it difficult to upgrade individual components (e.g. NHibernate) off t...

NHibernate Criteria Query vs. LINQ to NHibernate

I understand that there are queries you can't express in LINQ to NHibernate that you can using NHibernate Criteria. But, as far performance, is it safe to assume that using NHibernate Criteria is generally better than LINQ to NHibernate? ...

NHibernate join and projection properties

Hello, I have simple situation (like on the image link text) and simple SQL query SELECT M.Name, A.Name, B.Name FROM Master M LEFT JOIN DetailA A ON M.DescA = A.Id LEFT JOIN DetailB B ON M.DescB = B.Id How to achive the same effect in nHibernate using CriteriaAPI ? I have something like this: public c...

Linq to NHibernate, Order by Rand() ?

Hi everybody, I'm using Linq To Nhibernate, and with a HQL statement I can do something like this: string hql = "from Entity e order by rand()"; Andi t will be ordered so random, and I'd link to know How can I do the same statement with Linq to Nhibernate ? I try this: var result = from e in Session.Linq<Entity> orderb...

Fluent NHibernate: Mapping a column with a different name

Let's say I have a table: Project Id Title ProjectManagerId ContactId ProjectManagerId and ContactId are both id's from a table named Person: Person PersonId Firstname Lastname How can I map these two columns to create a person object? (either using automapping or fluent's normal mapping). Thanks ...

Trouble when trying to use Nhibernate.Linq

I have been trying to implement Nhibernate.Linq 1.0.0.4000 together with Nhibernate 2.1.2.4000. After what I've read that should be a straightforward process - just adding a reference to Nhibernate.Linq and then start querying with Session.Linq<>.. So.. In my repository I added a very simple query: var query = (from l in _session.Lin...

Nhibernate Linq Error on Single or Default

I'm pulling my hair out over here and I'm not sure what's causing it. I have the following LINQ query: return Session.Linq<CandidateAccountEntity>().SingleOrDefault(p => p.UserName.ToLower().Equals(userName.ToLower())); and its throwing the following error: Index was out of range. Must be non-negative and less than the size of...

Is there a coherent way to use ICriteria and Linq to NHibernate in the same query?

It looks like this question: NHibernate.Linq and MultiCriteria provides a potential way to combine using Linq to NHibernate and ICriteria together in the same query (in my case, to add fulltext search predicates to Linq to NH queries). If you wrapped the Linq to NHibernate IQueryable<T> with your own implementation, you could even inc...

Linq to NHibernate - The method Cos is not implemented

In Linq to NHibernate I'm trying to return businesses within a certain distance of a user. Here is what I have so far: var query = from b in ActiveRecordLinq.AsQueryable<Business>() where (3959 * Math.Acos(Math.Cos((Math.PI * coordinates.Latitude / 180)) * Math.Cos((Math.PI * b.Latitude / 180)) ...

NHibernate.Linq -> The method CompareTo is not implemented

Here's the problem: in short I use comb.guid identity strategy and I need all the rows made after the saved marker.. Here's dummy code example of what I am trying to get: return session.Linq .Where(p => p.Id.CompareTo(lastSyncedEntityIdentity) == 1 ) .ToList(); This throws an excep...