linq-to-nhibernate

How to compare just the date, not the timestamp using LINQ

I'm trying to compare just the date of a column but because the query below is also comparing the time I get no result set back. How could I write this same LINQ query if I'm only interested in the actual date value matching? The column "ImportDate" has a value that looks similar to this 2009-08-30 12:26:00 from t in UnitsOfWork _ whe...

Unique results from joined queries with NHibernate LINQ provider

I'm using NHibernate 2.1 with the LINQ provider and the results I get back from this query have multiple root nodes: public IList<Country> GetAllCountries() { List<Country> results = (from country in _session.Linq<Country>() from states in country.StateProvinces orderby country.Dis...

Eager loading child and child-of-child collections in NHibernate

I've got a problem with NHibernate trying to load a small hierarchy of data. My domain model looks like: class GrandParent { int ID{get;set;} IList<Parent> Parents {get; set;} } class Parent { IList<Child> Children {get; set;} } class Child { } and I would like to eager load all parents and children for a given GrandPar...

Has anyone every received a "Unhandled Expression Type: 1004" using Linq to NHibernate?

I have a linq query that is passed into NHibernate which Linq2NHibernate will parse and return me populated entities. string firstName = "Ryan"; Store store = _repository.Query<Store>().Where(x => x.Employees.Select(y => y.FirstName).Contains(firstName)).FirstOrDefault(); The troublesome part is x => x.Employees.Select(y => y.FirstNam...

NHibernate.Linq LockMode

Is it possible to set the LockMode when using NHibernate.Linq? When using ICriteria I can this way: var criteria = Session.CreateCriteria<Foo>(); criteria.SetLockMode(LockMode.None); criteria.Add(Expression.Eq("Title", title)); Is it possible to build that same query using Nhibernate.Linq? ...

nhibernate query with child entities and lazy="false"

Hi All I have a problem with seperate sql queries being generated for every item in a child collection when selecting the Parent. I have a Parent object with an IList collection of Child objects. If I run the following code using linq to nhibernate: IList parents = _repository.ToList(); I get the sql statements like the following: S...

Linq to Nhiberate - Where clause

I have tried to find an answer to this, but could not find one in google. Probably not searching the correct terms, so thought I would ask here. The following returns all my contacts, not the ones that equal the adjusterType sent in. var contacts = from c in session.Linq<Contact>() select c; contacts.Where(c => c.ContactAdjuster.Adjus...

Select n+1 problem

Foo has Title. Bar references Foo. I have a collection with Bars. I need a collection with Foo.Title. If i have 10 bars in collection, i'll call db 10 times. bars.Select(x=>x.Foo.Title) At the moment this (using NHibernate Linq and i don't want to drop it) retrieves Bar collection. var q = from b in Session.Linq<Bar>() ...

FluentNHibernate RTM and NHibernate.Linq

Hi, I've had a system up and running that used the Fluent NHibernate pre-release v0.0.1.0 along with NHibernate 2.1.0.4000 and NHibernate.Linq 1.0.0.0. I've just put in the new Fluent NHibernate RTM dlls and fixed my code for the breaking changes but I'm getting a couple of issues dependant on how I try to implement. 1) If I don't cha...

ADO.NET Data Services querying against LINQ to NHibernate: "Could not understand: (IIF(([1003] = null), null, Convert([1003].Contains("name"))) = null)"

I'm trying to perform a simple query using ADO.NET Data Services running against LINQ to NHibernate. I can execute this query var query = _context.CreateQuery("FileDTOs") .Where(file => file.Name.Contains("name")); I can run a similar query directly against LINQ to NHibernate without issues, but when I pass the same q...

Linq To NHibernate: .StartsWith on multiple properties

Hi, I'm trying to accomplish the following query (notice .StartsWith): return (from p in _session.Linq<Profile>() where (p.Firstname + " " + p.Lastname).StartsWith(wildcard) select p).ToList(); This throws: could not resolve property: Firstname.Lastname. If I do this: return (from p in _session.Linq<Profile>() ...

Group by date with LINQ to NHibernate

I am facing an issue with an unsupported feature in the LINQ implementation of NHibernate (it's firing a QueryException: "could not resolve property: CreatedOn.Date of: Example.Comment"). Given the entity below, I would like to extract statistics by grouping the comments per day and sum up the amount of comments for each day (naturally ...

How to handle NHibernate LINQ empty result set?

I want to retrieve list of roles for a logged in user. Following is a code segment that reads user roles from the database. ISession session = NHibernateHelper.GetCurrentSession(); var data = from s in session.Linq<ApplicationUserRole>() where s.AppUser.ID = 1 select s.Role.Name; ...

Linq to nhibernate - Having where clause problems

I am using linq-to-nhibernate with the following query: ISession session = GetSession(); var query = from storeZoneStyles in session.Linq<StoreZoneStyle>() from storeZones in session.Linq<StoreZone>() where storeZoneStyles.StoreZoneId == storeZones.StoreZoneId && storeZones.StoreCode == storeCode select storeZoneStyles; ...

Linq-to-NHibernate OrderBy Not Working

I'm trying order a Linq to NHibernate query by the sum of it's children. session.Linq<Parent>().OrderBy( p => p.Children.Sum( c => c.SomeNumber ) ).ToList() This does not seem to work. When looking at NHProf, I can see that it is ordering by Parent.Id. I figured that maybe it was returning the results and ordering them outside of SQL,...

Linq to NHibernate projections? AliasToBeanTransformer?

Is there any way, using NHibernate 2.1 and Linq to Nhibernate 1.0, to use projections? Something like AliasToBeanTransformer in a criteria query? ...

NHibernate.Linq LIKE

How can I produce this query using NHibernate.Linq? WHERE this_.Name LIKE @p0; @p0 = 'test' // Notice NO % wild card Note, this is not Linq To Sql or Entity Framework. This is NHibernate. Edit: Here is the desired query using ICriteria: criteria.Add(Expression.Like("Name", "test")); return criteria.List<Theater>(); ...

Why is NHibernate Linq duplicating results?

I have a simple Nhibernate Linq query that is returning more results than expected: var result = (from foo in session.Linq<Foo>() where foo.High.ID == High.ID select foo).ToArray(); Foo looks like this: public class Foo : DomainLayerSuperType { // ...other members omitted for clarity ...

Linq to NHibernate: Distinct

I am trying to get the following SQL output using Linq-to-NHibernate: SELECT DISTINCT Name, at.Year FROM MyTable mt INNER JOIN AnotherTable at ON at.Id = mt.AnotherTableId The Name and Year properties are going to be wrapped up in a new class, so the C# code will look something like this: Session.Linq() .Select(x => new FooBar { N...

Null Reference exception in NHibernate.Linq AssociationVisitor constructor

I keep encountering the following error when using NHibernate.Linq System.NullReferenceException: Object reference not set to an instance of an object. at NHibernate.Linq.Visitors.AssociationVisitor..ctor(ISessionFactoryImplementor sessionFactory) at NHibernate.Linq.NHibernateQueryProvider.TranslateExpression(Expression expression) at N...