linq-to-nhibernate

NHibernate.QueryException: could not resolve property

Hello all, I'm using FluentNHibernate and Linq To Nhibernate, with these entities (only the relevant parts): public class Player : BaseEntity<Player> { private readonly IList<PlayerInTeam> allTeams = new List<PlayerInTeam>(); public IEnumerable<Team> Teams { get { return from playerInTeam in all...

Linq for NHibernate strange Count() behavior

Hi everyone, I have what strikes me as a very unusual behavior from Linq for NHibernate. In general, all my entity classes are working just fine, but one of them throws a "NonUniqueResult" exception from the NHibernate namespace under the following condition. If I call the following: getSession<MyClass>().Linq<MyClass>().Count(); ...

Dynamic linq library with linq to nhibernate: is it working?

Hello, in one of my project I want to replace linq to sql with linq to nhibernate but I'm facing a strange issue when I use dynamic queries (with the dynamic linq library). With linq2SQL the following code works but not with linq2nhibernate, at the second apps.Count() nhibernate raises an exception: A first chance exception of type 'Sy...

Linq to NHibernate repository implementation details

I'd like to have the following API for my MyTypeRepository: var myChosenInstance = _myRepository.FindOne(x => x.MyProperty == "MyValue"); ..and for the lambda to use used to construct a linq query within the repository, which is then used by Linq to NHibernate. Is this possible? What would my repository FindOne method look like? ...

LINQ-to-NHibernate Filter IQueryable by Composite Field - "Could not resolve property" error

Quick background - I have a form that offers a handful of optional options to users and a search method on my service that accepts all those fields and attaches the necessary Where() conditions on the master IQueryable list. One of those filters is a list of strings that must be compared to a combination of three different fields in t...

NHibernate - "In" query with composite id

I'm trying to perform an "in" query on a collection of id objects (implemented as a simple class with two integer id members) which are mapped as composite-keys and I'm seeing some strange results when I query using the criteria api using Restrictions.In and using NHibernate.Linq using idList.Contains Here is a sample usage: Public...

How do you return certain properties from a linq query, rather than complete objects?

Hi all I've just downloaded the Linq provider for NHibernate and am just a little excited. But I don't know Linq syntax that well. I can return whole objects from a query like this: var query = from foo in session.Linq<Kctc.BusinessLayer.Domain.Case>() where foo.CaseNumber > 0 select foo; And I ca...

Linq to nhibernate question

Hi, I'm trying to create a query using linq 2 nhibernate which generate a sql like: select * from table where id in (1, 2, 3, 4) At the moment I have this code: var vouchers = Session.Linq<Voucher>() .Where(x => campaignIds.Contains(x.VoucherGroup.Campaign.Id)) .ToA...

Nhibernate createsqlquery from different db won't persist

I first try and pull the customer from the db, but if my customer doesn't exist, then i make a sql call another db on the server to get the information. I'd like to then save the customer info in my db. The Session is currently hooked up to my db. var customer = Session.Linq<Customer>().FirstOrDefault(x=>x.customernumber == cusotmerNu...

Limiting fields in Select statement generated by Linq to Castle ActiveRecord

Hi all! I'm using ActiveRecord and LinqToActiveRecord to query my database. The problem is, that the generated SQL statement from my LINQ expression always tries to select all possible fields, including joined tables, when this is not needed. For example, I have these database tables: Table: MasterTable Id (int) ChildId (int) <- refere...

Nhibernate Linq 3 In Clause

It seems that a In clause is not working properly with Linq 3.0 (trunk) I tried following: var l = session.Query.Where(p => searchGroups.Contains(p.ID)).Select(r=>r); I get an exception that says that the Binary operator for \"System.Collections.Generic.ICollection`1[System.Int32]\" and \"System.Int32 is not defined With Linq 1.0 it w...

Why does Linq to Nhibernate produce an outer join

I have an issue with Linq to Nhibernate producing queries with outer joins. For example: return Session.Linq<ClientContact>().Where(c => c.Client.Id = 13).ToList(); Produces a query similar to: SELECT... FROM mw_crafru.clientcontact this_, mw_crafru.client client1_, mw_crafru.relationshiptype relationsh4_ WHERE t...

NHibernate/LINQ - Aggregate query on subcollection

Querying child collections has been a recurring issue in our applications where we use NHibernate (via LINQ). I want to figure out how to do it right. I just tried forever to get this query to work efficiently using LINQ, and gave up. Can someone help me understand the best way to do something like this? Model: ServiceProvider ...

Starts with doesn't work in Linq to NHibernate query

In my repository I have: public IQueryable<ICustomer> GetByAddress(string address) { return from c in GetSession().Linq<ICustomer>() where c.Address.StartsWith(address) select c; } The SQL I'd like it to generate is essentially: SELECT * FROM Customer WHERE address LIKE @address + '%' However, whenever I d...

Selecting CompostiteUserTypes with Linq To nHibernate (v1)

Hi, We've a mature nHibernate project that has started using the linq provider in nHibernate contrib. As we are using nHibernate 2.0 we can't use the new provider under development in the trunk (against nHibernate 3.0). Whilst limited it's proved to be a perfect for our needs apart from one issue - whenever I select a CompositeUserType...

NHibernate - how to query against subclass properties while returning the super class?

Using NHibernate; is it possible to query against a super class while performing restrictions at the subclass level? For example (appologies for the psuedo-code): Class A Property Prop1 End Class Class B Inherits Class A Property Prop2 End Class Class C Inherits Class A Property Prop3 End Class How would I perform a ...

Adding calculated properties to class throws NHibernate error when using Linq to NHibernate

Hello, I added some calculated read-only properties to my class and it's now throwing a QueryException: could not resolve property. Here is my class (fake calculations right now): public class IncompleteApplication : DealerBase { public virtual string Content { get; set; } public virtual string LegalBusinessName ...

Fluent NHibernate or NHibernate for Linq?

Fluent NHibernate or NHibernate, Which one should we prefer for linq support? ...

Does anyone know why Take() isn't working here

i have the following code using Nhibernate.Linq var apps = Session.Linq<History>().OrderByDescending(r => r.LastUpdated).Take(50); Console.Write(apps.Count()); the count returns 1000 (NOT 50 which is what i would have expected) any ideas why the .Take() is not working? ...

Is this the right way of using ThenFetch() to load multiple collections?

I'm trying to load all the collections eagerly, using NHibernate 3 alpha 1. I'm wondering if this the right way of using ThenFetch()? Properties with plural names are collections. The others are just a single object. IQueryable<T> milestoneInstances = Db.Find<T, IQueryable<T>>(db => from mi in db whe...