queryover

Nhibernate could not resolve property exception when using QueryOver, works on QueryAll

孤者浪人 提交于 2019-11-29 09:46:38
问题 I have the following problem Basically I have the 2 snippets below: var contactAssociation = session.QueryOver<ContactAssociation>(() => contactAssociationAlias) .Where(() => contactAssociationAlias.Contact.ID == careGiverId && contactAssociationAlias.Client.ID == clientKey) .Where(() => contactAssociationAlias.AclRole.RoleName == "Care Giver") .SingleOrDefault(); and var contactAssociation = session.Query<ContactAssociation>() .Where(cr => cr.Contact.ID == careGiverId && cr.Client.ID ==

Are there any arithmetic operation projections in NHibernate?

こ雲淡風輕ζ 提交于 2019-11-29 09:40:15
问题 I would like to get this SQL from NHibernate: SELECT SUM(color_pages) * SUM(total_pages) FROM connector_log_entry GROUP BY department_name But I can't find any arithmetic operation (*) projections anywhere. This is the code that I have so far: Session.QueryOver<ConnectorLogEntry>() .SelectList(list => list .SelectGroup(m => m.DepartmentName) .WithAlias(() => dto.Department) .Select(Projections.Sum<ConnectorLogEntry>(m => m.TotalPages)) //.Select(Projections.Sum<ConnectorLogEntry>(m => m

Adding conditions to outer joins with NHibernate ICriteria/QueryOver query

强颜欢笑 提交于 2019-11-29 08:32:08
Is there a way to specify additional conditions on outer joins in NHibernate when querying using QueryOver or ICriteria? I need some extra conditions on the outer join-ed table, but NHibernate always adds them to the WHERE clause at the end - which does not get the correct behaviour (see http://weblogs.sqlteam.com/jeffs/archive/2007/05/14/criteria-on-outer-joined-tables.aspx ). I can't seem to find any way to do this using Criteria or the QueryOver syntax... Thanks You probably figure out this long time ago. Solution is to add ICriteria parameter in JoinAlias method, like this: Party

NHibernate QueryOver with ManytoMany

徘徊边缘 提交于 2019-11-29 04:37:45
I'm in the process of learning QueryOver, but I can't for my life figure out how to do simple many to many queries. I've written the following: var result = Session.CreateCriteria(typeof (Product)) .CreateAlias("Categories", "categories") .Add(Property.ForName("categories.Id").Eq(categoryId)) .List<Product>(); This achieves the desired result. Basically I have Product > ProductCategory < Category ProductCategory just has ProductId / CategoryId, and I'm trying to select all the products in a specific category. I have no idea where to start with trying to do this with queryover. I ended up

Use OR Clause in queryover in NHibernate

拥有回忆 提交于 2019-11-29 04:06:12
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 Radim Köhler Here is description how we can build OR with NHiberante NHibernate QueryOver with WhereRestriction as OR The syntax (in C# as the tag says) is: Restrictions.Or(restriction1, restriction1) Restrictions.Disjunction()

nhibernate queryover join with subquery to get aggregate column

杀马特。学长 韩版系。学妹 提交于 2019-11-29 04:02:52
I have been searching for several hours now how to do this, but can't seem to find anything to help me. Here is the database model: This is the SQL query I am trying to run: SELECT b.*, a.Assignments FROM Branch b LEFT JOIN ( SELECT b.BranchID , COUNT(ab.BranchID) AS Assignments FROM Branch b LEFT JOIN AssignmentBranch ab ON b.BranchID = ab.BranchID GROUP BY b.BranchID ) a ON b.BranchID = a.BranchID So, basically, I want to return a list of branches and a new column that represents the number of assignments for that branch. Branch model public class Branch : IEntity<int> { public virtual int

NHibernate lazy loading nested collections with futures to avoid N+1 problem

允我心安 提交于 2019-11-28 19:38:12
I have an object model that looks like this (pseudo code): class Product { public ISet<Product> Recommendations {get; set;} public ISet<Product> Recommenders {get; set;} public ISet<Image> Images {get; set; } } When I load a given product and want to display the images of its recommendations, I run into an N+1 problem. (The recommendations are lazy-loaded, then a loop calls the .Images property of each one.) Product -> Recommendations -> Images What I want to do is eagerly load this particular part of the graph, but I can't figure out how to do it. I can load the recommendations eagerly, but

How to “Select” with nhibernate queryover

做~自己de王妃 提交于 2019-11-28 18:26:38
I want to use query over to give me back an object public class TaskMap : ClassMap<Task> { public TaskMap() { Table("Tasks"); Id(x => x.TaskId); Map(x => x.TaskName).NvarcharWithMaxSize().Not.Nullable(); Map(x => x.Description).NvarcharWithMaxSize(); Map(x => x.DueDate).Not.Nullable(); HasMany(x => x.PersonalTaskReminders).Inverse(); HasMany(x => x.TaskReminders).Inverse(); References(x => x.Course).Not.Nullable(); HasMany(x => x.CompletedTasks); } } [Serializable()] public class Task { public virtual int TaskId { get; private set; } public virtual string TaskName { get; set; } public virtual

Preventing multiple instance after inner join

隐身守侯 提交于 2019-11-28 14:07:58
I have a small problem with multiple instances of the same object after a join to an other table. For testing I create one Store with two Products (ManyToMany-Relation). The following snippet hopefully describes my problem. var preResult = _session.QueryOver<Store>().List(); // One store Product productAlias = null; var result = _session.QueryOver<Store>() .JoinAlias(s => s.Products, () => productAlias) .List(); // Two instances of the same store I even think this behavior is correct but how can I prevent the multiple instances? Is it possible within the query? Just for information why I need

Kendo grid server side grouping

浪尽此生 提交于 2019-11-28 11:43:10
I am using Asp net 5, NHibernate 3.3 and Kendo UI MVC wrapper for grid to render the table of client orders. There are lots of orders in database already and the number is constantly growing. So I decided to use server side paging to avoid fetching all orders from database. As far as I know you can't do paging manually and delegate filtering, sorting and grouping to ToDataSourceResult method. It's either all or nothing. Therefore I made an attempt to implement so called 'custom binding' . No problem until I get to grouping. I need to group first, then sort inside of a group, then extract data