linq-to-nhibernate

Problem with linq query

送分小仙女□ 提交于 2019-12-09 05:02:29
问题 I'm trying to use linq to NHibernate (with Fluent NHibernate) but I have problems with linq query. Everytime I try to execute it I get this message : " Method 'get_IsReadOnlyInitialized' in type 'NHibernate.Linq.Util.DetachedCriteriaAdapter' from assembly 'NHibernate.Linq, Version=1.1.0.1001, Culture=neutral, PublicKeyToken=null' does not have an implementation. " Does anybody know how to fix this problem? I tried with solution form this page with model context but it didn't help. This is the

Extending LINQ to Nhibernate provider, in combination with Dynamic LINQ problem

心不动则不痛 提交于 2019-12-08 23:56:34
问题 I'm using NHibernate 3.1.0 and I'm trying to extend the LINQ provider by using BaseHqlGeneratorForMethod and extending the DefaultLinqToHqlGeneratorsRegistry as explained in Fabio's post. For example, to support ToString() I've created a ToStringGenerator as below. internal class ToStringGenerator : BaseHqlGeneratorForMethod { public ToStringGenerator() { SupportedMethods = new[] { ReflectionHelper.GetMethodDefinition<object>(x => x.ToString()) }; } public override HqlTreeNode BuildHql

In Linq-to-Nhibernate, is it possible to use .Fetch() after a .Select()?

北城余情 提交于 2019-12-08 16:26:26
If I had an Object A that contained a many-to-one reference to Object B, where Object B contained a one-to-many collection of Object C... consider the following query: IQueryable<A> query = getIQueryableSomehow(); List<B> resultList = query.Where(A => A.whatever == something).Select(A => A.B).Fetch(B => B.C).ToList(); I want to do something similar to this, but I keep getting a null reference exception with this code. Is there a sneaky trick to achieve this kind of query AND fetch a bunch of Object B collections, or is it impossible? Thanks! you can specify Fetch before to load all A,B,C and

How to set timeout for NHibernate LINQ statement

假如想象 提交于 2019-12-08 15:02:46
问题 I am using Fluent NHibernate for my ORM. In doing so I am trying to use the NHibernate LINQ syntax to fetch a set of data with the power of LINQ. The code I have works and executes correctly with the exception being that a timeout is thrown if it takes longer than roughly 30 seconds to run. The question I have is how do I extend the default 30 second timeout for LINQ statements via NHibernate? I have already seen the posts here, here, and here but the first two refer to setting the

Bidi associations and NHibernate mapping

我的未来我决定 提交于 2019-12-08 07:37:27
问题 I have classes BidiParent and BidiChildList which link parents and children in a bidirectional parent-child relationship. If a child's parent is updated by e.g. the service layer, the old and new parents' children lists are automatically updated to reflect the change. Likewise, if a parent's children list is updated by e.g. adding a new child, the child's parent is automatically changed as is the old parent's children list. I want to try to build up a "smart" domain model. First question,

Cacheable(), FetchMany() and ToFuture() in same NHibernate Linq query

房东的猫 提交于 2019-12-08 02:18:23
问题 Having a situation similar to the following example: 1 parent entity Employee having 2 child collections: Addresses and Phones I need to retrieve in a single roundtrip all employees with their Addresses and Phones initialized and also cache the query that achieves that in level 2 cache using Cacheable() . Using: var baseQuery = session .Query<Employee>() .Cacheable(); baseQuery .FetchMany(e => e.Addresses) .ToFuture(); var list = baseQuery .FetchMany(e => e.Phones) .ToFuture() .ToList();

Bidi associations and NHibernate mapping

微笑、不失礼 提交于 2019-12-07 18:18:28
I have classes BidiParent and BidiChildList which link parents and children in a bidirectional parent-child relationship. If a child's parent is updated by e.g. the service layer, the old and new parents' children lists are automatically updated to reflect the change. Likewise, if a parent's children list is updated by e.g. adding a new child, the child's parent is automatically changed as is the old parent's children list. I want to try to build up a "smart" domain model. First question, obviously, is: is this even a good idea? Second question is: is it possible to tell NHibernate to access

Group by using linq with NHibernate 3.0

筅森魡賤 提交于 2019-12-07 15:08:30
问题 As far as I know group by has only been added in NHibernate 3.0, but even when using version 3, I can't get group by to work. I have tried to do the following query: Session.Query().GroupBy(gbftr => gbftr.Tag).OrderByDescending(obftr => obftr.Count()).Take(count).ToList(); But I receive the following error: Antlr.Runtime.NoViableAltException'. [. OrderByDescending (. GroupBy (NHibernate.Linq.NhQueryable `1 [Forum.Core.ForumTagRelation] Quote ((gbftr,) => (gbftr.Tag)),), Quote ((obftr,) => (.

Expression type 'NhSumExpression' is not supported by this SelectClauseVisitor

非 Y 不嫁゛ 提交于 2019-12-07 14:44:12
问题 I have a query that I can run in LinqPad, but not in NHibernate LINQ. I found a similar bug on NHibernate Jira NHibernate NH-2865, but I think this perhaps a different bug and I'm looking for possible alternatives. The query that works in LinqPad using default LINQ to SQL is like this: from ticket in LotteryTickets group tiket by ticket.ticketType into g select new { TicketType = g.Key, TotalWinningTickets = g.Count(b => b.WinAmount != 0), TotalWon = g.Sum(b => b.WinAmount * b.ticketWeight),

NHibernate Linq Query with Projection and Count error

本小妞迷上赌 提交于 2019-12-07 07:37:58
问题 I have the following query: var list = repositoy.Query<MyClass>.Select(domain => new MyDto() { Id = domain.Id, StringComma = string.Join(",", domain.MyList.Select(y => y.Name)) }); That works great: list.ToList(); But if I try to get the Count I got an exception: list.Count(); Exception NHibernate.Hql.Ast.ANTLR.QuerySyntaxException A recognition error occurred. [.Count[MyDto](.Select[MyClass,MyDto](NHibernate.Linq.NhQueryable`1[MyClass], Quote((domain, ) => (new MyDto()domain.Iddomain.Name