queryover

NHibernate Future<T> with Get()

馋奶兔 提交于 2019-12-01 08:25:28
问题 How can I use Future for delayed execution with Get() to retrieve a single record (or Load()?) Also, can I use Future with a detached QueryOver 回答1: Future with Load does not make any sense, as Load does not go to the DB. Future with get doesn't make sense either, as Get returns an instance which might already be loaded, in which case it doesn't go to the DB either. The closest you can get to that is a query by id. In order to get a Future<T> you need an executable query (Criteria/QueryOver

How can QueryOver be used to filter for a specific class?

非 Y 不嫁゛ 提交于 2019-12-01 08:05:24
I am currently dynamically constructing queries like so: QueryOver<Base, Base> q = QueryOver.Of<Base>(); if (foo != null) q = q.Where(b => b.Foo == foo); // ... Now there are multiple mapped subclasses of Base (e. g. Derived ) which I want to filter on, basically something like: if (bar) q = q.Where(b => b is Derived); // does not work or: if (bar) q = q.Where(b => b.DiscriminatorColumn == 'derived'); // dito How do I best achieve that, preferably - but not neccessarily - in a type-safe way? Can this be done using LINQ, too? This is not intuitive, but the following should work fine (QueryOver)

How to do a QueryOver in Nhibernate on child collection

限于喜欢 提交于 2019-12-01 07:32:25
Hello I have one Class named Notifications which is a child class for the User. public class User { public int Id { get; set; } public string Name { get; set; } public string UserName { get; set; } public ICollection<UserNotification> UserNotifications { get; set; } } public class Notification { public int Id { get; set; } public ICollection<UserNotification> UserNotifications { get; set; } public string Title { get; set; } public string Message { get; set; } public bool IsRead { get; set; } public DateTime CreatedDate { get; set; } } public class UserNotification { public User User { get; set

How can QueryOver be used to filter for a specific class?

邮差的信 提交于 2019-12-01 04:36:59
问题 I am currently dynamically constructing queries like so: QueryOver<Base, Base> q = QueryOver.Of<Base>(); if (foo != null) q = q.Where(b => b.Foo == foo); // ... Now there are multiple mapped subclasses of Base (e. g. Derived ) which I want to filter on, basically something like: if (bar) q = q.Where(b => b is Derived); // does not work or: if (bar) q = q.Where(b => b.DiscriminatorColumn == 'derived'); // dito How do I best achieve that, preferably - but not neccessarily - in a type-safe way?

How to do a QueryOver in Nhibernate on child collection

落爺英雄遲暮 提交于 2019-12-01 04:27:56
问题 Hello I have one Class named Notifications which is a child class for the User. public class User { public int Id { get; set; } public string Name { get; set; } public string UserName { get; set; } public ICollection<UserNotification> UserNotifications { get; set; } } public class Notification { public int Id { get; set; } public ICollection<UserNotification> UserNotifications { get; set; } public string Title { get; set; } public string Message { get; set; } public bool IsRead { get; set; }

Nhibernate + QueryOver: filter with Where ignoring sensitive

早过忘川 提交于 2019-12-01 03:18:55
I am trying to build a simple query in nHibernate with QueryOver but I want it to convert everything lower-case or ignore sensitive: Domain.User User = Session.QueryOver<Domain.User>() .Where(x=>x.Login=="username") .SingleOrDefault(); How can I achieve this? UPDATE : Someone suggested that the problem could be with the colletion of the DB but I've never had any kind of problem with that and this script works: Domain.User User = Session .CreateCriteria<Domain.User>() .Add(Expression.Eq("Login", "username")) .UniqueResult<Domain.User>(); In QueryOver you can use following: Domain.User User =

Crossjoin using QueryOver

半腔热情 提交于 2019-12-01 01:37:09
How could I replace the HQL query below using QueryOver API? var sql = "from Role r, Action a where r.Active = :active and a.Active = :active"; var result = manager.Session.GetISession().CreateQuery(sql) .SetBoolean("active", true).List(); I don't believe there's a way to do this in QueryOver, since both JoinAlias and JoinQueryOver require an expression describing a path to the related entity. However, this is easy to accomplish in LINQ-to-NHibernate: var result = (from role in manager.Session.GetISession().Query<Role>() from action in manager.Session.GetISession().Query<Action>() where role

Crossjoin using QueryOver

老子叫甜甜 提交于 2019-11-30 19:32:41
问题 How could I replace the HQL query below using QueryOver API? var sql = "from Role r, Action a where r.Active = :active and a.Active = :active"; var result = manager.Session.GetISession().CreateQuery(sql) .SetBoolean("active", true).List(); 回答1: I don't believe there's a way to do this in QueryOver, since both JoinAlias and JoinQueryOver require an expression describing a path to the related entity. However, this is easy to accomplish in LINQ-to-NHibernate: var result = (from role in manager

NHibernate QueryOver Subquery

荒凉一梦 提交于 2019-11-30 19:27:36
I've looked at the similar questions, but can't find a simple explanation. I could have missed it, but I promise I looked. Actually I can't even find the documentation other than a single blog post that glosses over everything rapidly and assumes you're familiar with other forms of NH. Given a many-to-many between Program and Topic , where the latter is in a hierarchy of Topics , I want to retrieve all the Programs for a given Topic , possibly including its subtopics. Since a program may be listed under multiple sub-topics of a given parent topic, I need to use a subquery or deal with having

Mocking out nHibernate QueryOver with Moq

只谈情不闲聊 提交于 2019-11-30 18:56:58
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(_mockSession.Object, _mockCommandRunner.Object, _mockDirectory.Object, _mockFile.Object, _mockConfig.Object);