linq-to-nhibernate

Linq to NHibernate and Group By

試著忘記壹切 提交于 2019-12-02 13:31:53
问题 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 developerGroup select new {developerGroup.Key.Name, Count = developerGroup.Count()} Enumerating this query causes an exception - "could not resolve property Key of

How to compare just the date, not the timestamp using LINQ

北慕城南 提交于 2019-12-02 10:30:44
I'm trying to compare just the date of a column but because the query below is also comparing the time I get no result set back. How could I write this same LINQ query if I'm only interested in the actual date value matching? The column "ImportDate" has a value that looks similar to this 2009-08-30 12:26:00 from t in UnitsOfWork _ where t.ImportDate = "08/30/2009" _ select t You can compare it as a string or you can use just the Date property on ImportDate where t.ImportDate.ToString("yyyyMMdd") == "20090830" or where t.ImportDate.Date == new DateTime(2009,8,30) 来源: https://stackoverflow.com

Linq to NHibernate and Group By

老子叫甜甜 提交于 2019-12-02 06:11:18
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 developerGroup select new {developerGroup.Key.Name, Count = developerGroup.Count()} Enumerating this query causes an exception - "could not resolve property Key of Entities.VideoGame". Now, if I group by v.Developer.Id it works, but I can't select the Name column and

Nhibernate Linq query to QueryOver

∥☆過路亽.° 提交于 2019-12-02 05:01:39
I have the following piece of code: 1: ids = GetAnArrayOfIds(); 2: jobEntities = jobEntities.Where(j => j.Locations.Select(l => l.Id).Any(ids.Contains)); How do I write 2 using QueryOver ? Thank you, var results = session.QueryOver<Job>() .JoinQueryOver<Location>(u => u.Locations) .Where(loc => loc.Id.IsIn(ids)) .TransformUsing(Transformers.DistinctRootEntity) .List(); Hope this helps 来源: https://stackoverflow.com/questions/6997146/nhibernate-linq-query-to-queryover

linq (to nHibernate): 'like in' operator

匆匆过客 提交于 2019-12-02 02:23:48
Hi Given a list of strings I want to retrieve all items whose names contain one of the given strings. for example- given {"foo", "kuku"} I want to retrieve the employees "Corfoo", "kuku maluku" and "kukufoo". I've tried the following, but got a null-reference exception(?) query.Where(u => values.Any(v=> u.FullName.Contains(v)) ); The following produced a 'Lambda expression not in scope' exception. query.Where(u => (values.Count(v => u.FullName.Contains(v)) > 0) ); any idea how this can be done? I was thinking along the lines of iterating over the values collection and adding a new condition

NHibernate aggregate query for one-to-many relation

时间秒杀一切 提交于 2019-12-02 02:12:39
问题 I have next entities: class Topic { public virtual int Id {get; private set;} public virtual ICollection<Vote> Votes {get; private set; } } class Vote { public virtual Topic Topic {get; private set;} public virtual VoteType VotedTo {get; private set;} // enum VotedUp, VotedDown } I need to load from the db the next info - all topics (IDs, actually Names, but in this demo case it does not matter) and two more fields CountOfVotedUp, CountOfVotedDown (aggregates) . So as I understand in SQL

Conditional operator in Linq Expression causes NHibernate exception

青春壹個敷衍的年華 提交于 2019-12-01 17:32:06
I'm trying to implement search functionality in an ASP.NET MVC 2 application. I create an expression based on criteria entered by the user: public ViewResult FindCustomer( string forename, string familyname, DateTime? dob) { Expression<Func<Customer, bool>> searchCriteria = p => ( forename.IsNullOrEmpty() ? true : p.Forename == forename && familyname.IsNullOrEmpty() ? true : p.FamilyNames.Any(n => n.Name == familyname) && dob.HasValue ? true : p.DOB == dob ); which then gets passed to a method in the repository IQueryable<Customer> customers = CustomerRepository.FilterBy(searchCriteria); The

Fetching records by date with only day part comparison using nhibernate

不想你离开。 提交于 2019-12-01 17:09:10
I would like to fetch all records from particular day, no matter what time is associated with those records. So far I have method like this: public IQueryable<Record> QueryByDay(DateTime day) { DateTime from = day.Date; DateTime to = day.Date.AddDays(1); return repository.Table .Where(t => t.MyDate >= from && t.MyDate < to); } But in linq-to-object we can do (assuming Table is now some collection): public IEnumerable<Record> QueryByDay(DateTime day) { return repository.Table .Where(t => t.MyDate.Date == day.Date); } Which is obviously more readable and feels more clean. I was wondering if

Fetching records by date with only day part comparison using nhibernate

寵の児 提交于 2019-12-01 16:46:35
问题 I would like to fetch all records from particular day, no matter what time is associated with those records. So far I have method like this: public IQueryable<Record> QueryByDay(DateTime day) { DateTime from = day.Date; DateTime to = day.Date.AddDays(1); return repository.Table .Where(t => t.MyDate >= from && t.MyDate < to); } But in linq-to-object we can do (assuming Table is now some collection): public IEnumerable<Record> QueryByDay(DateTime day) { return repository.Table .Where(t => t

Order by relation count in NHibernate

烂漫一生 提交于 2019-12-01 14:58:37
I have a datastructure like this: public class User { public Guid Id {get;set;} public string Name {get;set;} public IList<Books> Books {get;set} } I have been struggeling with making it possible to sort the users by the count of bookmarks (one-to-many relation). I have tried various approaches with both linq, criteria and queryover, but with no luck, and therefore hope one of you could help. I am using paging, since I have quite a few users, so the solution needs to do the query on the SQL and not in memory on the webserver. var loadedUser = session.Query<User>() .Select(u => new { u, u.Books