linq-to-nhibernate

NHibernate and LINQ - InvalidOperationException: "Could not find entity named ..."

Have a look at the following tests: [TestMethod] public void CanRead() { using (ISession session = OpenSession()) { var criteria = session.CreateCriteria(typeof(Action)); var result = criteria.List<Action>(); Assert.IsTrue(result.Count > 0); } } [TestMethod] public void CanReadWithLinq() { using (ISession...

Does a function call in the Where(...) clause of a Linq to Nhibernate query negatively affect performance?

I use linq to nhibernate and the IQueryable.Where function in an application I'm building. And what mystifies me is how do the Expressions I create and pass to the Where function of a INhibernateQueryable affect performance. I'm not really sure what are the gotchas I should avoid in writing these query Expressions, in terms of perfor...

Can't get Linq to NHibernate to work

Hi all, I'm struggling with getting Linq To NHibernate to work. I have referenced NHibernate, NHibernate.Linq and NHibernate.ByteCode.Castle . Also I have all other dependencies in the same folder. Code / Error message: Public Function GetProjectsByName(ByVal ProjectName As String) As List(Of Project) Return (From x In _session....

Linq.NHibernate problem with OR statement

NOTE: all the code is written Top of my head. It can contains some mistakes. Just get the overall point of this question) Taking this class definition: (reduced for simplicity) public class CodedValue { public string Code { get; set; } public string Value {get; set; } } Taking thoses objects: CodedValue cv1 = new CodedValue(){ C...

How to check query statement in Linq to NHibernate?

I'd like to see sql query once linq to nhibernate query is executed to log or check sql query. How can I do? ...

Castle ActiveRecord using Linq to Nhibernate Example

I have been using the ActiveRecord library for many years. Recently I started a new project and I'm including the AR 2.0 release in this project. I saw that it shipped with the Linq to Nhibernate library. Are there any good examples of how to use Linq to Nhibernate with the Active Record library? ...

How to check converted sql query in linq to NHibernate?

I am using Linq to NHibernate. I have a following test case : [TestMethod] [DeploymentItem("hibernate.cfg.xml")] public void Category_Should_GetAllByLinq() { // Arrange IRepository<Category> repo = new CategoryRepository(); //Act IList<Category> list = repo.GetListByLinq(); //Assert Assert.IsTrue(list.Count > 0); } and ...

NHibernate: How do I ignore the cache and go directly to the database?

Consider a typical NHibernate context class. public class SampleContext : NHibernateContext { public SampleContext(ISession session) : base(session) { } public IQueryable<Person> People { get { return Session.Linq<Person>(); } } public Person GetPerson(int id) { get { return Session....

NHibernate Linq uses implicit transaction?

I'm using Ayende's NHibernate Linq version 2.1.2, available here, and when I use NHProf to inspect queries that use this method: public IQueryable<T> GetAll() { return Session.Linq<T>(); } It gives me the warning that I'm using an implicit transaction. Problem is, I'm using this in a repository to abstract out the database session...

Linq to Nhibernate question

Consider this 3 classes public class ClassA { public IList<ClassB> BList {get; private set;} } public class ClassB { public ClassC C {get; private set;} } public ClassC { //doesn't matter } I want to get all ClassA instances from the repository, that has at least one BList element containing a specific C instance, that i...

Linq to NHibernate : is it mature ?

Hi, I'm thinking about using Linq to NHibernate in an upcoming project, so I'd like some feedback about it. I found this identical question asked in February, and it seemed that Linq to NHibernate was not very mature at this time... Has it improved since then ? Has anyone used it in real life applications ? Thanks for your feedback PS...

Do some of Castle ActiveRecord's LINQ operators not work?

I'm working with an object model in Castle ActiveRecord that represents pregnant women. It's a simple tree structure: Patient Visit Delivery A Patient has 0 or more Visits and a Visit has 0 or more Deliveries. I've mapped everything to the database, and I can loop through the Patient>Visit>Delivery hierarchy and print out ever...

Linq to NHibernate and Group By

I'm using the current Linq provider for NHibernate (version 2.1). I have two entities: VideoGame and GameDeveloper, with a many-to-one relationship between them. I'm trying to perform a query of this sort, which counts the number of video games each game developer has: from v in session.Linq<VideoGame>() group by v.Developer into devel...

NHibernate fetching the superclass brings the subclasses along

Hi, i have this code to get a ClassA from the database, and ClassA is superclass of ClassB. (ClassB : ClassA) var query = from classA in GetQuerySession().Linq<ClassA>() where classA.Code.Equals(code) select classA; return query.FirstOrDefault(); ClassA and ClassB are mapped to ...

Select parent and count of children in Nhibernate using Linq in the same query

I am trying to learn MVC and nHibernate by creating a simple blog application. I have a posts table and a comments table. Each post can have multiple comments. Now in my view I have to display the details of the post and the number of comments. I tried the below code (from post in DbContext.Posts where post.ScheduledDate <= DateTim...

LINQ-NHibernate - Selecting only a few fields (including a Collection) for a complex object

I'm using Fluent NHibernate in one of my projects (and ASP.NET MVC application), with LINQ to query to data (using the LINQ to NHibernate libraries). The objet names are changed to protect the innocent. Let's say I have the following classes Foo, Bar, Baz, and their appropriate tables in the database (MySQL). Foo has a many-to-many re...

Linq To NHibernate Plus sql user defined function

I have a rather large linq-to-nhibernate query. I now need to add a filter based on a user-defined function written in t-sql that i have to pass parameters into. In my case, I need to pass in a zipcode that the user types in and pass it to the t-sql function to filter by distance from this zip. Is this possible, or do i need to rewri...

NHibernate.Linq System.Nullable throws ArgumentException, the value "" is not type ...

I have a class of type MetadataRecord: public class MetadataRecord { public virtual long? IntegerObject { get; set; } public virtual string ClassName { get; set; } public virtual DateTime? DateObject { get; set; } public virtual double? DecimalObject { get; set; } public virtual long MetadataId { get; set; } publ...

NHibernate filter criteria - Hour of DateTime

I am having hard times convincing NHibernate (EF was able to do it) to filter based on the Hour property of a DateTime entity property. My entity goes something like : public class Invoice { // ... public DateTime Time { get; set; } // ... } I need to retrieve all the invoices that were "made" at a certain hour (let's say ...

Linq-to-NHibernate String/DateTime Conversion in Where

I'm just starting out with Linq to NHibernate and having troubles with a pretty simple query. I have a database column that is defined as a varchar. In the linq query I need to compare that value to a datetime value (all of the values stored in the varchar column are valid dates). I'm trying this: var list = (from o in session.Linq<O...