linq-to-nhibernate

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

。_饼干妹妹 提交于 2019-12-06 21:52:17
问题 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 where mi.RunDate == runDate select mi).Fetch(mi => mi.Milestone) .ThenFetch(m => m.PrimaryOwners) .Fetch(mi => mi.Milestone) .ThenFetch(m => m.SecondaryOwners) .Fetch(mi => mi.Milestone) .ThenFetch(m

Convert anonymous type to new C# 7 tuple type

我只是一个虾纸丫 提交于 2019-12-06 16:36:36
问题 The new version of C# is there, with the useful new feature Tuple Types: public IQueryable<T> Query<T>(); public (int id, string name) GetSomeInfo() { var obj = Query<SomeType>() .Select(o => new { id = o.Id, name = o.Name, }) .First(); return (id: obj.id, name: obj.name); } Is there a way to convert my anonymous type object obj to the tuple that I want to return without mapping property by property (assuming that the names of the properties match)? The context is in a ORM, my SomeType object

Get item index (rownum)

六眼飞鱼酱① 提交于 2019-12-06 09:51:15
I have table with 10 000 elements. IQuerable<IEntity> query = dataRep.Get<IEntity>() .Query(); I need to get the index(rownum) of selected obj without getting all table items var obj = query.Where( x => x.Name == "testName") .FirstOrDefault(); The simple sql work fine : select name, id, r from ( select name, id, rownum r from collections order by id ) where name = 'testName'; How do this in Linq to NHibernate ? Edit: I tried add to IEntity class property RowNumber and mapping this on hbm as <property name="RowNumber" formula="rownum" /> But after var index = query.Where( x => x.Name ==

NHibernate Linq Eager Loading with generic repository

荒凉一梦 提交于 2019-12-06 06:48:45
问题 Currently we are using a generic repository for all our entities that exposes an IQueryable (using NH3 linq support) that is then used by our service layer to construct specific queries. I now need to eagerly load an association. Is there any way I can expose an IQueryable and pass in optional fetch expressions? The problem I see is that Fetch must come last in the expression (as per http://mikehadlow.blogspot.com/2010/08/nhibernate-linq-eager-fetching.html). I'm curious as to how others have

FirstOrDefault() breaks FetchType=join with Linq to NHibernate

邮差的信 提交于 2019-12-06 06:38:36
If i do Session.Linq<MyClass>().Where(x => x.Id = someId).FirstOrDefault(); where MyClass has a set of eager loaded child object on it, the FirstOrDefault() seems to prevent this from working by adding a TOP 1 to the SQL. Is this just a bug (feature?) in Linq2NH (which i understand is being rewritten) or am I missing something? Is there a preferred alternative which works properly? Thanks Looks like a bug, in my opinion FirstOrDefault is a pretty well defined Linq operator and it has nothing to do with eager/lazy loading, so it should not break it. I guess there are lots of such nuances, which

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

孤者浪人 提交于 2019-12-06 06:21:49
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(); should work, but I get the following exception: NHibernate.PropertyAccessException Message: Exception

Latest Binary builds of FLuentNhibernate + Nhibernate + Linq for NHibernate

喜欢而已 提交于 2019-12-06 05:26:03
问题 do people build there own versions of all this? or is there a place to get all this prebuilt? I got the latest FluentNhibernate which has NHibernate but no Linq.... but I don't really want to setup a ruby rake build system etc etc unless I really really have to! Prefer to just get all the binaries I need. 回答1: Here is a build: http://www.dennisdoomen.net/2009/07/nhibernate-210-ga-with-linq-and-fluent.html 回答2: I build my own versions, because I don't want to be forced to upgrade all the

Linq to NHibernate extensibility for custom string query operations?

大兔子大兔子 提交于 2019-12-06 04:28:25
问题 I would like to be able to use custom string querying within my NHibernate Linq expressions. Let's say for example (and this is just an example) I would like to be able to select entities containing a property which is an anagram of a particular string: var myEntities = EntityRepository.AllEntities.Where(x => x.Description.IsAnagramOf('hits'); I imagine the steps involved in this process would be: Define a SQL Server UDF to determine whether two strings are anagrams. Define an extension

Expression type 'NhSumExpression' is not supported by this SelectClauseVisitor

不问归期 提交于 2019-12-06 04:23:29
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), TotalTickets = g.Count(), } There are various other ways to count the TotalWinningTickets such as

Group by using linq with NHibernate 3.0

青春壹個敷衍的年華 提交于 2019-12-06 00:24:17
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,) => (. Count (obftr,))),)] Does anyone have an idea if I might be mistaken, and group by isn't implemented in