linq-to-nhibernate

LINQ to NHibernate - .GroupBy().Skip().Take() cause an exception

≯℡__Kan透↙ 提交于 2020-01-14 14:16:14
问题 NHibernate version 3.3.1.4000 Query: IQueryable<Activity> activities = _repository.GetList<Activity>(); IQueryable<ActivityStatistic> statistics = activities .GroupBy(activity => activity.ActivityLicense.SerialNumber) .Select(grouping => new ActivityStatistic { ActivityCount = grouping.Count(), LicenseCode = grouping.Key }) .OrderBy(stat => stat.LicenseCode); List<ActivityStatistic> result = statistics .Skip(request.StartIndex) .Take(request.Count) .ToList(); If I comment Skip/Take code, it

LINQ to NHibernate - .GroupBy().Skip().Take() cause an exception

两盒软妹~` 提交于 2020-01-14 14:16:07
问题 NHibernate version 3.3.1.4000 Query: IQueryable<Activity> activities = _repository.GetList<Activity>(); IQueryable<ActivityStatistic> statistics = activities .GroupBy(activity => activity.ActivityLicense.SerialNumber) .Select(grouping => new ActivityStatistic { ActivityCount = grouping.Count(), LicenseCode = grouping.Key }) .OrderBy(stat => stat.LicenseCode); List<ActivityStatistic> result = statistics .Skip(request.StartIndex) .Take(request.Count) .ToList(); If I comment Skip/Take code, it

linq (to nHibernate): 'like in' operator

↘锁芯ラ 提交于 2020-01-11 10:22:08
问题 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

Linq: select property collection

我的未来我决定 提交于 2020-01-04 13:47:43
问题 I have two classes: public class Person { public int Id{get;set;} public string Name{get;set;} public List<Order> Orders{get;set;} } public class Order { public int Id{get;set;} public string Data{get;set;} public decimal Sum{get;set;} } I use Nhibernate Linq. If I want to get total sum of orders filtering by Persan.Name I do this: var result = (from person in personRepository.Query from order in person.Orders where person.Name.Contains("off") select order).Sum(order => order.Sum); How can I

Linq: select property collection

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-04 13:47:08
问题 I have two classes: public class Person { public int Id{get;set;} public string Name{get;set;} public List<Order> Orders{get;set;} } public class Order { public int Id{get;set;} public string Data{get;set;} public decimal Sum{get;set;} } I use Nhibernate Linq. If I want to get total sum of orders filtering by Persan.Name I do this: var result = (from person in personRepository.Query from order in person.Orders where person.Name.Contains("off") select order).Sum(order => order.Sum); How can I

NHibernate join and projection properties

一世执手 提交于 2020-01-04 06:26:49
问题 I have simple situation (like on the image link text) and simple SQL query SELECT M.Name, A.Name, B.Name FROM Master M LEFT JOIN DetailA A ON M.DescA = A.Id LEFT JOIN DetailB B ON M.DescB = B.Id How to achive the same effect in nHibernate using CriteriaAPI ? I have something like this: public class Employee : ClassBase, IContactData { public virtual string FirstName { get; set; } public virtual string MiddleName { get; set; } public virtual string LastName { get; set; } public virtual string

Eager loading child and child-of-child collections in NHibernate

女生的网名这么多〃 提交于 2020-01-01 12:48:46
问题 I've got a problem with NHibernate trying to load a small hierarchy of data. My domain model looks like: class GrandParent { int ID{get;set;} IList<Parent> Parents {get; set;} } class Parent { IList<Child> Children {get; set;} } class Child { } and I would like to eager load all parents and children for a given GrandParent. This Linq-to-NH query creates the correct SQL and loads the GrandParent as expected: (the example assumes the grandparent has 2 parents who each have 2 child objects - so

NHibernate.Linq LIKE

耗尽温柔 提交于 2020-01-01 03:56:07
问题 How can I produce this query using NHibernate.Linq? WHERE this_.Name LIKE @p0; @p0 = 'test' // Notice NO % wild card Note, this is not Linq To Sql or Entity Framework. This is NHibernate. Edit: Here is the desired query using ICriteria: criteria.Add(Expression.Like("Name", "test")); return criteria.List<Theater>(); 回答1: With NH 4 (and probably a bit earlier), a built-in Like string extension is available within NHibernate.Linq namespace: Like(this string matchExpression, string sqlLikePattern

Nhibernate Linq query to QueryOver

落爺英雄遲暮 提交于 2019-12-31 03:44:04
问题 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, 回答1: 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

How to a NHibernate subquery in Where clause with LINQ?

狂风中的少年 提交于 2019-12-25 04:12:28
问题 I'm trying to write a correlated subquery in the where clause like this: var foo = from d in session.Query<Document>() where true == ( from a in session.Query<ACLEntry>() where a.Id == d.Id || a.Id == null select a.Result ).FirstOrDefault() select d; The expected SQL output is very similar to this unanswered question on SO. I think the Linq statement itself is fine because I can get it to run in LinqPad where I was prototyping. But NHibernate throws me these mysterious errors: ERROR