Questions tagged [linq-to-nhibernate]

A provider for NHibernate library for .NET Framework which allows to use LINQ queries. Available since version 3.0.

629 questions
0
votes
2 answers

Fetch Eager NHibernate failed to lazily initialize a collection

Im dealing with N+1 problem, and I want to eager load a collection in an especific query, but I am getting the "failed to lazily initialize a collection" error, or the query keep lazy loading. I have tried many suggestions given by stackmembers but…
0
votes
1 answer

How do I querying over one-to-many relationship in NHibernate?

Given the code: public class Audit { public Audit { Details = new List(); } public virtual IList Details { get; set; } public virtual string SourceFile { get; string } public virtual DateTime Timestamp {…
LEMUEL ADANE
  • 8,336
  • 16
  • 58
  • 72
0
votes
1 answer

Overwrite HQL-generation for FetchMany()

I know that I can extend NHibernates HQL-generation to support new methods as described in this article. If I implement IRuntimeMethodHqlGenerator it will also work for generic methods. But is there a way to overwrite NHibernate's default behavior…
Sebastian Weber
  • 6,766
  • 2
  • 30
  • 49
0
votes
2 answers

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(); …
Marc Wittke
  • 2,991
  • 2
  • 30
  • 45
0
votes
1 answer

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() where foo.High.ID == High.ID select foo).ToArray(); Foo looks like…
Noel Kennedy
  • 12,128
  • 3
  • 40
  • 57
0
votes
2 answers

Linq 2 NHibernate ignoring conditions

I got this query var pc = _session.Query() .Where(x => x.Valutum.ValutaBetegn == updateLine.ProductCurrency) .Fetch(x => x.Valutum) .OrderByDescending(x => x.ValutaHistoryID) .First(); But it results to this SQL: select TOP (1)…
Alexey Zimarev
  • 17,944
  • 2
  • 55
  • 83
0
votes
1 answer

Linq Nhibernate left join

A Theft has an action property This is the query i'm trying to get NHibernate.Linq to produce: SELECT * FROM `thefts` LEFT JOIN memberThefts ON thefts.id = memberThefts.theftId AND memberThefts.memberId = 1 I want to get a list of all the thefts…
Juddling
  • 4,594
  • 8
  • 34
  • 40
0
votes
1 answer

NHibernate Fetch when querying for single object

I'm trying to optimize an NHibernate query: var profile = dc.Profiles.FirstOrDefault(p => p.IdProfile == idProfile); I would like it to load a collection of Rights. I did this: var profile = dc.Profiles.Fetch(x => x.Rights).FirstOrDefault(p =>…
kubal5003
  • 7,186
  • 8
  • 52
  • 90
0
votes
2 answers

How to a NHibernate subquery in Where clause with LINQ?

I'm trying to write a correlated subquery in the where clause like this: var foo = from d in session.Query() where true == ( from a in session.Query() where a.Id == d.Id || a.Id == null …
Ragesh
  • 2,800
  • 2
  • 25
  • 36
0
votes
1 answer

Linq query condition on self-referencing entity

I am trying to retrieve all entities of type Queried from the database where Referenced property or it's ancestor for which its label (meaning referenced.Parent.ChildLabel) is equal to some given label value exampleLabel, has an Id equal to…
Răzvan Flavius Panda
  • 21,730
  • 17
  • 111
  • 169
0
votes
1 answer

NHibernate: HqlGenerator: Create calculated property by concatenating other properties

I am trying to add an HqlGenerator to allow NHibernate to query a calculated property on the following domain entity: public class User { public string FirstName { get; set; } public string LastName {get; set; } public string FullName …
Aaron Janes
  • 304
  • 3
  • 11
0
votes
1 answer

Issue when quering Hierarchy to Hierarchy relationship

A Teacher has a one-to-one with a Student. A SpecialTeacher extends Teacher but deals specifically with SpecialStudents. Using table per class in the hierarchies. public class Teacher { public virtual int Id { get; set; } …
Rezler
  • 1,064
  • 1
  • 8
  • 21
0
votes
2 answers

Dynamically composing LINQ expressions

Is it possible to combine dynamically expressions: from c in collection where c.Property == true select c with expression from result in results group result by result.Property into g select new g.Key where 'results' should be the collection…
petrov.alex
  • 1,089
  • 2
  • 12
  • 20
0
votes
1 answer

NHibernate: Handling Select() on empty result sets

Invoking the following query when there is no Entity record in the database throws a NotSupportedException var list = session.Query() .OrderBy(x => x.TranslationTime) .Take(10) .Select(x…
twoflower
  • 6,788
  • 2
  • 33
  • 44
0
votes
2 answers

How to prevent Nhibernate from fetching derived class?

I am using Nhibernate and I have a problem when fetching a base class with multiple derived classes (each class mapping a different table). When I watch the request, Nhibernate joins on every derived tables which has a huge an impact on the…