queryover

NHibernate QueryOver Subquery

左心房为你撑大大i 提交于 2019-12-09 00:34:33
问题 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

QueryOver - add restriction on primitive collection

半腔热情 提交于 2019-12-08 23:03:30
Given the following entity- public class Friend { public virtual string Name { get; set; } public virtual IEnumerable<string> Nicknames { get; set; } } which is mapped like so: mapping.HasMany(x => x.Nicknames).Element("Value") //this gets auto-mapped to a different 'Nicknames' table given a string, I want to retrieve friend who's name or one of his nicknames matches that string. I can't figure out how to do that.. here's what I've got so far: .Where(Restrictions.Or( Restrictions.On<Friend>(f => f.Name).IsInsensitiveLike(name), Restrictions.On<Friend>(f => f.Nicknames) // i'd like to be able

Nhibernate QueryOver nested properties

戏子无情 提交于 2019-12-08 12:24:23
问题 Is there an easy way to use QueryOver with nested properties? For example, I try something like this; // SPLAT! session.QueryOver<SuperHero>().Where(Expression.Eq("HomeBase.Name", "Bat Cave"); It won't work because it 'could not resolve property 'homebase.name' of SuperHero. That makes sense, but there is obviously some way to make this work, because if I use the older 'Query' approach I can get it to work just fine, i.e. // The results I (technically) want. sess.Query<SuperHero>().Where(x =>

Joining two tables with specific columns in nhibernate

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-08 11:35:05
问题 I have two table: Customers and Products public class Customers { public virtual int Id { get; set; } public virtual string CName { get; set; } public virtual int Age { get; set; } public virtual string Address { get; set; } public virtual int Salary { get; set; } } public class Product { public virtual int Id { get; set; } public virtual string PName { get; set; } public virtual Customers CustomerID { get; set; } public virtual int Amount { get; set; } } whit this Values in DB: -----------

Dynamic Where condition with Queryover

蓝咒 提交于 2019-12-08 04:33:23
问题 I have an application and I'm trying to implement DDD concepts. I have my repository class with some method to list entities. I would like to know how can I do a query with QueryOver to filter separating with AND operator, when the parameter is filled, sample public IEnumerable<Product> FindProducts(string name, decimal? price, DateTime? validDate, int? stock, int? idSupplier) { var query = Session.QueryOver<Product>().OrderBy(x => x.Name).Asc; if (!string.IsNullOrEmpty(name)) // add where

Nhibernate Group By and Alias To Bean

故事扮演 提交于 2019-12-08 04:30:38
问题 I have been struggling to get an old query translated to Nhibernate. We are upgrading an old project from Nhibernate 2 to the latest version. I am using the QueryOver syntax since Linq wasn't an option because of the complexity of the queries (advice of a colleague). I want to query the DB (Oracle) to get some results which have to be grouped. As result I need a grouped collection of my DTO. I also noticed that nhibernate has trouble translating to a DTO with complex properties (nested DTO's)

Dynamic QueryOver in nHibernate

人走茶凉 提交于 2019-12-08 03:54:49
问题 Similar to 'Dynamic LINQ OrderBy' I would like to make a dynamic QueryOver-OrderBy. However, when I do this: query.OrderBy(h => h.GetType().GetProperty(sort.Member).GetValue(h, null)).Asc I get an exception which says: Unrecognised method call in epression h.GetType().GetProperty(value(Domain.Model.Repository+<>c__DisplayClass15).sort.Member).GetValue(h, null) Apparently, nHibernate has some trouble understanding what's going on. Does anyone have an idea on how to solve this particular issue?

QueryOver - add restriction on primitive collection

可紊 提交于 2019-12-08 03:26:02
问题 Given the following entity- public class Friend { public virtual string Name { get; set; } public virtual IEnumerable<string> Nicknames { get; set; } } which is mapped like so: mapping.HasMany(x => x.Nicknames).Element("Value") //this gets auto-mapped to a different 'Nicknames' table given a string, I want to retrieve friend who's name or one of his nicknames matches that string. I can't figure out how to do that.. here's what I've got so far: .Where(Restrictions.Or( Restrictions.On<Friend>(f

QueryOver Many to Many with a single SQL join

我们两清 提交于 2019-12-08 01:30:00
问题 I've got 2 entities, linked many-to-many. (Product & User) I want to restrict Products by Users: User userAlias = null; query.JoinAlias(product => product.Users, () => userAlias) .Where(() => userAlias.Id == currentUser.Id); It's generated SQL code: SELECT this_.Id as y0_ FROM [Product] this_ inner join UserToProduct users5_ on this_.Id = users5_.Product_id inner join [User] useralias3_ on users5_.User_id = useralias3_.Id .... In "Where" i use only user_id and i don't need second join. How I

NHibernate child collection Projection to DTO

倖福魔咒の 提交于 2019-12-07 22:30:35
问题 I have had a good look around for answers on this, and several questions suggest this cannot be done. Nhibernate projection with child collection NHibernate QueryOver projections - projecting collections to DTO NHibernate Projections - how to project collections So I was wondering what would be a good work around to project a child collection to my DTO. Will I need to run two seperate projections and manually add the children to the parent? I am using NH 3.3.1 I have the following DTO data