linq-to-nhibernate

Linq to NHibernate query issue

Why would the following work: var profiles = (eventId > 0) ? Profiles.Query().Where(p => p.Event.Id == eventId).ToList() : Profiles.Query().Where(p => p.Event == null).ToList(); when the following will not: var profiles = (from p in Profiles.Query() where (eventId > 0) ? p.Event.Id == event...

NHibernate - How to write this Query: Select parents & find child for each parent that matches a condition

OK, first my simple Domain Model is 2 classes with a one-to-many relationship, a simple Parent -> child relationship. A 'Tweet' has one or more 'Votes', but each Vote belongs to just one Tweets etc. public class Tweet { public virtual long Id { get; set; } public virtual string Username { get; set; } public virtual string Me...

A simple Linq To NHibernate Query

What I'm trying to achieve must be simple but I just can't get it to work. I have a simple table that contains an id and a description field. Something like so: Medium ----------- Id Description ---------- 1 Watercolour 2 Oil 3 Etching 4 Other Because a user will have the opportunity to pick any of t...

NHibernate 3 LINQ not assigning variables correctly

Hello, I'm attempting to use NHibernate 3.0.0 Alpha 2 and I'm running into issues with the LINQ provider. If I do a simple query such as var query = rep.AvailableProjects.Where(o => o.RequestorId == searchDto.RequestorId && o.ProcessCd == searchDto.ProcessCd); I get the following SQL as output: select table0_.REQUESTOR_ID as REQUEST...

Using LINQ-to-NHibernate Sort an IQueryable of T based on a property value within T's Children

Though the project in which I'm having this issue addresses a different domain, I've found a metaphor that may help to present my question clearly: Let's say that you had to develop a Forum web site, and it was a requirement that the default view for the site needs to display Forum Threads ordered by the threads with the most recent For...

NHibernate.Linq count throws NHibernate.QueryException : could not resolve property

I'm building an ecommerce site using S#arp Architecture. I'm trying to map a hierachy of categories and retrieve the top level categories. I'm using NHibernate.Linq for this. I have the following entity: public class Category : Entity { #region Properties [DomainSignature] [NotNullNotEmpty] public virtual string Name {...

Fluent NHibernat - Querying enum field with LINQ

Hi, my application has the following database structure: Transactions: - TransactionID (PK, Identity, Int) - TypeID (FK, Int) - Amount (Decimal) TransactionTypes: - TypeID (PK, Identity, Int) - Type (NVarChar) The are defined in my application as: public class Transaction { public virtual int TransactionID { get; set; } publ...

Nhibernate linq where clause with boolean value

If I try to add a where clause, containing a lambda filter on a boolean field, to a nhibernate linq query, the filter seems to be ignored: var result = Session.Linq().Where(x=> x.Approved); Session is an iSession and Newspaper is a simple object with the fields NewspaperId int, Name - varchar(50) and Approved - bit. When I run this th...

Using nhibernate to filter by the value of an object in a child collection.

Here's the setup. NHibernate, Fluent NHibenrate and Nhibernate Linq The entities invoved are Fault - a record of a fault occuring Alarm - information about the fault, think of it as a fault type ( a list of all possible faults that can occur ) AlarmDescription - human readable description, one for each language A fault has an alar...

How to optimize this Nhibernate Query (835ms)

I have this query var temp = from x in ActiveRecordLinq.AsQueryable<Circuits>() where x.User_Created == false orderby x.Description select x; From NHibernate Profiler Query duration -Database only: 7ms -Total: 835ms The query generated: SELECT this_.Circuit...

Composite Id's and Restrictions.IdEq or with comparison in Linq not working as expected

I have an entity where a composite id is used. I changed to code to make use of wrapping the composite id in a seperate key class. I expected that with Linq I could do a comparison on key object and with the Criteria API to use Restrictions.IdEq but both fail. I need to explicitly compare the key values to make it work. I cannot find an...

nhibernate - sproutcore : How to only retrieve reference ID's and not load the reference/relation ?

Hi All, I use as a front-end sproutcore, and as back-end an nhibernate driven openrasta REST solution. In sproutcore, references are actualy ID's / guid's. So an Address entity in the Sproutcore model could be: // sproutcore code App.Address = App.Base.extend( street: SC.Record.attr(String, { defaultValue: "" }), houseNumber: SC.R...

Fluent NHibernate Cacheing for Linq queries

I have just discovered that I don't think my nhibernate setup seems to be cacheing properly. I'm running a SQL server profiler and neither the 1st or 2nd level cache appear to be working. For my queries I'm using: var queryable = NHibernateSession.CurrentFor(NHibernateSession.DefaultFactoryKey).Linq<Accommodation>(); queryable.QueryOpt...

NHibernate 3 - extending Linq provider BaseHqlGeneratorForMethod.BuildHql problem

I want to extend the default LINQ provider for NHibernate 3 with methods of my own. I want to be able to use some methods from my POCOs. I have a component named Range which is used quite often in many of my POCOs. This nhibernate component class has a method Contains(int value) that I want to use in LINQ query expressions Mapping: <cl...

LINQ query does not work without .ToList()

Consider following LINQ-to-NHibernate queries: var q1 = from se in query.ToList<SomeEntity>() where prop1 == "abc" select se; var q2 = from se in q1 where m1(se.prop2) == "def" select se; q2 will not work with error: "The method m1 is not implemented". But when replace q2 with following query, everything goes ok: var q...

NHibernate - LINQ Limitations

Hi, i've been using Nhibernate with LINQ a fair bit now and i have a few issues. Say i have the following entities: public class User { public virtual int UserID { get; set; } public virtual bool IsActive { get; set; } public virtual bool SomeField { get { return 0; } } public virtual DateTime DateRegistered { get; set;...

Why no SQL for NHibernate 3 Query?

Why is no SQL being generated when I run my Nhibernate 3 query? public IQueryable<Chapter> FindAllChapters() { using (ISession session = NHibernateHelper.OpenSession()) { var chapters = session.QueryOver<Chapter>().List(); return chapters.AsQueryable(); } } If I run the quer...

Why Skip and Take does not work when passing through a method?

Suppose following codes: IEnumerable<MyClass> MakeQuery() { var query = from m in session.Linq<MyClass>() select m; return query; } List<MyClass> m1() { return MakeQuery() .Skip(10) .Take(20) .ToList<MyClass>(); } List<MyClass> m2() { var query = from m in session.Linq<MyClass>() select ...

NHibernate LINQ throws "The binary operator Equal is not defined for the types 'System.Collections.Generic.IList`1[System.Int32]' and 'System.Int32'"

The following LINQ to NHibernate (using NHibernate 3.0) results in a System.InvalidOperationException being thrown with the message "The binary operator Equal is not defined for the types 'System.Collections.Generic.IList`1[System.Int32]' and 'System.Int32'" public IEnumerable<ProjectSummary> GetProjects( IList<int> clients ) { usin...

Getting an index was out of range exception with NHibernate

Hi all, I'm currently building a web application with MVC and NHibernate. Now when i want to get information out of the database I get an index was out of range exception. The current situation is as follows. I got the mapping files of three database tables: A table to store a group with a one-to-many relationship with subscriberingro...