queryover

Override lazy loading behavior 'lazy=false'

我怕爱的太早我们不能终老 提交于 2019-12-24 04:04:07
问题 I would like to override the default lazy loading behavior which is set in mappings as 'lazy=false'. Can't change it as many parts of existing application depend on this setting. After spent some hours on it I didn't find a solution so I'm asking here. How to do this? What I want to achieve is to fine tune my query to load only what is needed. This is what I've tried already: Using QueryOver api: var properties = session.QueryOver<Property>() .Fetch(prop => prop.Transactions).Eager .Fetch

NHibernate 3.2 QueryOver distinct by property

我只是一个虾纸丫 提交于 2019-12-24 02:59:14
问题 I have two classes public class News { public virtual int Id { get; protected set; } public virtual string Topic { get; set; } public virtual Category Category { get; set; } } public class Category { public virtual int Id { get; protected set; } public virtual string Name { get; set; } public virtual ISet<News> News { get; set; } } And mappings <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="News" namespace="NewsManagement.Models"> <class name="News" table="News"> <id name="Id

QueryOver error : Unrecognised method call in expression value

妖精的绣舞 提交于 2019-12-24 01:25:01
问题 I have a query by QueryOver in Nhibernate3.1 var q = SessionInstance.QueryOver<Person>() .Where(x => IsActive(x.PersonType) == true); return q.List<Person>(); By this method: private bool IsActive(PersonType type) { if(type == PersonType.Employee return true; else return false; } Now it has a runtime error by this message: Unrecognised method call in expression value Why? 回答1: I solved a similar problem by returning an expression tree in my predicate method instead of returning a boolean

Nhibernate QueryOver Orderby

≯℡__Kan透↙ 提交于 2019-12-24 00:45:59
问题 I'm trying to decouple the orderby on a queryover call and this doesn't compile protected static void AddOrder<T>(IQueryOver<T, T> criteria, Expression<Func<object>> expression ) { criteria.OrderBy(expression).Asc; } I'm guessing there is a way to do this, somehow bringing in the asc into the linq expression? Thanks for the help! 回答1: That's not how IQueryOver works... to make it compile, you'd have to do the following: protected static IQueryOver<T, T> AddOrder<T>(IQueryOver<T, T> criteria,

group by month and year parts using queryover

自作多情 提交于 2019-12-24 00:41:01
问题 I have a model, that contains a DateTime field and a Price field. I want to get a list that gives me an aggregation of month/year - price so for the data: 15/01/2012 200 16/01/2012 200 15/02/2012 300 16/02/2012 300 15/03/2012 400 16/03/2012 400 I will get: 01/2012 400 02/2012 600 03/2012 800 So far I didn't find a way to achive this using QueryOver. I keep getting "could not resolve property" when i try to look at the Month/Year parts of the date. Those questions: Group posts by year, then by

NHibernate COALESCE issue

久未见 提交于 2019-12-23 21:29:00
问题 I am trying to express the following SQL query with NHibernate DECLARE @date DATETIME = NULL; SELECT ER.Id , ER.DocumentDate FROM ExpenseReport ER WHERE ER.PeriodFrom >= COALESCE(@date, ER.PeriodFrom) OR ER.PeriodTo <= COALESCE(@date, ER.PeriodTo); So, in the C# part I do have the following classes: for the entity : ExpenseReport for my search itself a separate class Code snippets: // ----- Entity class. public partial class ExpenseReport { public Nullable<System.DateTime> PeriodFrom { get;

NHibernate QueryOver SQLFunction in where clause

天大地大妈咪最大 提交于 2019-12-23 17:53:04
问题 I would like to query a table having multiple rows, each with a timestamp with data coming at ten minute intervals. I would like to find the beginning of any missing data, which is where there is not a timestamp equaling the next ten minute interval, like this: select a.[timestamp] from [table] as a where not exists (select 1 from [table] as b where a.[id] = b.[id] and b.[timestamp] = dateadd(mi, 10, a.[timestamp])) order by a.[timestamp] I have this so far, but I fail to see how to build the

Using a subquery for a column with QueryOver

左心房为你撑大大i 提交于 2019-12-23 17:33:48
问题 I'm trying to get something similar to the SQL below via QueryOver: SELECT docs.*, (SELECT TOP 1 eventDate from events WHERE id=docs.id AND type=4 ORDER BY eventDate DESC) as eventDate FROM documents as docs WHERE doc.accountId = ... I've got close with a projection, however I'm not sure how to get the entire documents table back. Documents has a one-to-many relationship with Events, I don't want to outer join as it will bring multiple results, and an inner join may not bring back a row: var

GroupBy SqlFunction on QueryOver

丶灬走出姿态 提交于 2019-12-23 09:33:18
问题 I have a list of all distinct account name prefixes (a-z) which I acquire using var accounts = this.SessionManager.GetActiveSession().QueryOver<Account>(); var q = accounts.Select(Projections.Distinct( Projections.SqlFunction("substring", NHibernateUtil.String, Projections.Property("Name"), Projections.Constant(1), Projections.Constant(1)))); However what I want to do is instead of returning a distinct list is group the prefixes and return the number of accounts that start with that prefix,

Subqueries with QueryOver

爱⌒轻易说出口 提交于 2019-12-22 14:02:32
问题 I have a issue in using subquery with queryover. This is what I have var address = QueryOver.Of<Address>() .Where(x => x.City.IsLike("%" + city + "%")).Select(x => x.Person.Id); var result = Session.QueryOver<Person>() .Where(x => x.Type.IsLike(type + "%")) .And(x => x.Name.IsLike("%" + name + "%")) .WithSubquery.WhereExists(address); I have a table for Person and a person has multiple addreses. So Person id, name, type and Address will have PersonId and city etc. So want to search a person