queryover

Order by relation count in NHibernate

扶醉桌前 提交于 2019-12-19 12:12:08
问题 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

Implementing “where not exists” with NHibernate QueryOver

左心房为你撑大大i 提交于 2019-12-19 10:29:35
问题 Using the new QueryOver API in NHibernate, I need to do something equivalent of: select c.* from Category c where not exists ( select * from CategoryProduct cp where cp.CategoryID = c.Id and cp.ProductID = 'DogFood' ) In other words: "Give me all categories that doesn't contain dog food". My initial thought was something like: IEnumerable<Category> FindCategoriesWithoutProduct(Product product) { return _session .QueryOver<Category>() .Where(c => c.Products.Contains(product)) .List(); }

Nhibernate QueryOver collation without hard coded column name

醉酒当歌 提交于 2019-12-19 10:07:45
问题 So I have the following sql SELECT * FROM table Where Name COLLATE LATIN1_GENERAL_CI_AI LIKE 'myText%' which I want to implement using QueryOver At the minute I have: whereRestriction.Add(Expression.Sql("Name COLLATE LATIN1_GENERAL_CI_AI LIKE ?", String.Format("{0}%", subStringMatch), HibernateUtil.String)); which works fine, but with two issues. Firstly it's sqlserver specific and secondly the database column 'Name' is hardcoded. Has anyone any suggestions to get around these two problems,

How to do a conditional Sum with Nhibernate?

℡╲_俬逩灬. 提交于 2019-12-19 03:12:28
问题 I'm trying to do the equivalent of this SQL Code SELECT ID SUM(CASE WHEN myProperty = 2 THEN 1 ELSE 0 END) as nbRowWithValueOf2, SUM(CASE WHEN myProperty = 3 THEN 1 ELSE 0 END) as nbRowWithValueOf3 FROM Foo GROUP BY ID With Nhibernate. So far I tried queryable = queryable .Select( Projections.Group<Foo>(c => c.ID), Projections.Sum<Foo>(c => c.myProperty == MyEnum.Two ? 1 : 0) Projections.Sum<Foo>(c => c.myProperty == MyEnum.Three ? 1 : 0) ) But this gives me the following error: Could not

Mocking out nHibernate QueryOver with Moq

和自甴很熟 提交于 2019-12-18 20:18:35
问题 The following line fails with a null reference, when testing: var awards = _session.QueryOver<Body>().Where(x => x.BusinessId == (int)business).List(); My test is like so: var mockQueryOver = new Mock<IQueryOver<Body, Body>>(); mockQueryOver.Setup(q => q.List()).Returns(new List<Body> {_awardingBody}); _mockSession.Setup(c => c.QueryOver<Body>()).Returns((mockQueryOver.Object)); _mockCommandRunner = new Mock<ICommandRunner>(); _generator = new CertificateGeneratorForOpenSSLCommandLine(

Fluent NHibernate “Could not resolve property”

纵然是瞬间 提交于 2019-12-18 18:54:33
问题 I have read a lot of the questions about that same error but none since to match my exact problem. I'm trying to access the property of an object, itself part of a root object, using Fluent NHibernate. Some answers say I need to use projections, others that I need to use join, and I think it should work through lazy loading. Here are my two classes along with the Fluent mappings: Artist class public class Artist { public virtual int Id { get; set; } public virtual string Name { get; set; }

NHibernate QueryOver select entity and aggregates

只谈情不闲聊 提交于 2019-12-18 16:54:55
问题 What I want to do is display a simple grid of data which contains the entity data, and the aggregate data of its children. For example lets use a Order and line items. I want to display the order information, and the count of line items. OrderID, OrderDate, NumOfLineItems Now normally in SQL you can do it many ways. But this is the only way I could think of that might work when translating to NHibernate. SELECT o.OrderID, OrderDate, NumOfLineItems FROM #Orders o INNER JOIN (SELECT o2.OrderID,

NHibernate using QueryOver with WHERE IN

扶醉桌前 提交于 2019-12-18 10:27:39
问题 I would create a QueryOver like this SELECT * FROM Table WHERE Field IN (1,2,3,4,5) I've tried with Contains method but I've encountered the Exception "System.Exception: Unrecognised method call: System.String:Boolean Contains(System.String)" Here my code var qOver = _HibSession.QueryOver<MyModel>(() => baseModel) .JoinAlias(() => baseModel.Submodels, () => subModels) .Where(() => subModels.ID.Contains(IDsSubModels)) .List<MyModel>(); 回答1: I've found the solution!! :-) var qOver = _HibSession

NHibernate QueryOver with WhereRestriction as OR

冷暖自知 提交于 2019-12-18 09:12:09
问题 I have this query but I can't seem to find how I set my WhereRestrictionOn as an OR. Now they function as AND but I want one OR the other. var privateInfo = Session.QueryOver<ConContact>() .JoinAlias(c => c.PrivateInfos, () => pi) .WhereRestrictionOn(c => c.FirstName).IsLike(_selectedFirstLetter + "%") .WhereRestrictionOn(c => c.LastName).IsLike(_selectedFirstLetter + "%") // todo: change to firstname OR lastname .Where(c => c.Status == ContactStatus.Approved) .Select( Projections.Property(

Use OR Clause in queryover in NHibernate

江枫思渺然 提交于 2019-12-18 04:07:14
问题 I am using Nhibernate. I am writing query through queryover method. I am able to write and clause as in code below. Its working fine. db.QueryOver(Of Users)() .Where(Function(x) x.Role = "Guest") .And(Function(x) x.Block = 0) .And(Function(x) x.APPID = appId) .List(); But I want to use Or clause instead of And , or combination of both. How can I implement this. Thanks 回答1: Here is description how we can build OR with NHiberante NHibernate QueryOver with WhereRestriction as OR The syntax (in C