queryover

How can I select a column within a dictionary value with nhibernate?

纵然是瞬间 提交于 2019-12-07 19:41:39
问题 I have structure similar to this: public class Entity { public int Id { get; set; } public IDictionary<string, EntityLocale> Locales { get; set; } } public class EntityLocale { public string Name { get; set; } } public class EntityMap : ClassMap<Entity> { public EntityMap() { HasMany(x => x.Locales) .AsMap<string>("Locale") .Component( c => { c.Map(x => x.Name); } ); } } And I want to recieve all names of product locales with a "en" key. With linq it will be: var names = Session.QueryOver

NHibernate (+ FluentNhibernate) : Join two detached tables

百般思念 提交于 2019-12-07 17:56:54
问题 'tI encounter problems to create a join on two entities with a common property but they are not map together. Say you have an entity Article which contains a property FamilyCode and an entity Family with properties Code and Label. In my mappings, Article doesn't reference Family and i don't want to change that (to keep compatibility with others internal and legacy methods). So, i can't translate the below query in Nhibernate : SELECT f.Code, f.Label FROM Article a INNER JOIN Family f ON a

How to get List of Parent Entities with Child Count In Nhibernate QueryOver

烈酒焚心 提交于 2019-12-07 11:38:35
问题 I have two classes : public class Parent { public int Id { get; set; } public string Name { get; set; } public ICollection<Child> Childrens { get; set; } } public class Child { public int Id { get; set; } public string Name { get; set; } } Now through Nhibernate QueryOver I want to get list of all Parent with no of Count of children in single query. Expected output is ?: ParentId Name ChildrenCount 1 ABC 10 2 CDE 5 can anyone help me . 回答1: Using this DTO for projection: public class

Join multiple tables with NHibernate and QueryOver

自作多情 提交于 2019-12-07 09:22:40
问题 I have this tables: Person -> PersonFavorites, PersonCompany PersonCompany -> Company I have now to do the following select with NHibernate and QueryOver: select * from Person inner join PersonFavorites on Person.Id = PersonFavorites.PersonId inner join PersonCompany on Person.Id = PersonCompany.PersonId inner join Company on Company.Id = PersonCompany.CompanyId where ... Can someone give me a sample, how I can do that? - My Problem is, that I have to join multiple Tables Person ->

NHibernate QueryOver<> - Aggregate function over SubQuery

不羁的心 提交于 2019-12-07 03:55:29
问题 How can I write the following SQL statement using QueryOver<> syntax? SELECT COUNT(*) FROM ( SELECT FirstName,LastName FROM People GROUP BY FirstName, LastName ) as sub_t I have the inner query working so far: var q = _session.QueryOver<Person>() .SelectList(l => l .SelectGroup(x => x.FirstName) .SelectGroup(x => x.LastName)); But I have no idea how to wrap this in a subquery and get a row count out of it. Can it be done? Unfortunately my RDBMS dialect (MsSqlCe40Dialect) does not support

How to use Full Text Search for any property with QueryOver API

我是研究僧i 提交于 2019-12-07 03:09:51
问题 I'm trying to use the SQL function CONSTAINS to filter some data on QueryOver API. The main issue is i can't use SqlFunction in where clause, it does not compile, because a ICriterion is needed. var result = Session.QueryOver<Individual>() .Where(Projections.SqlFunction( "FullTextContains", NHibernateUtil.Boolean, Projections.Property<Individual>(x => x.LastName), Projections.Constant("something"))) .List(); I tried to match it to a TRUE constant, but when the query is executed it generates

Nhibernate Group By and Alias To Bean

别等时光非礼了梦想. 提交于 2019-12-06 18:59:26
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) To fix this I found this topic. This works great but I am not a fan of the magic strings... I will add

Queryover dynamic fetch with joins

半世苍凉 提交于 2019-12-06 12:07:01
iam trying a new query with nhibernate and find a new problem :( take this as model: public class D { int id; } public class C { int id; } public class B { int id; ICollection<C> Cs; ICollection<D> Ds; } public class A { int id; ICollection<B> Bs; } i want A object that have a particular B object and dinamically eager fetch Cs or Ds collection of selected B: public virtual A Read(int idB, params Expression<Func<Attivita, object>>[] eagerFields) i start with IEnumerable<A> query = _session.QueryOver<A>() .JoinQueryOver(a => a.Bs) .Where(b => b.Id == idB) .Future<A>(); foreach (Expression<Func<A

Fluent Nhibernate Composite Key Not Generating Joins For Referenced Entities

懵懂的女人 提交于 2019-12-06 11:18:15
问题 I have a mapping with a composite key as below: CompositeId() .KeyReference(x => x.CreatedBy, "member_key") .KeyReference(x => x.Box, "box_key"); This works fine for simple gets and inserts, however it is not generating joins with the tables mentioned in the reference where I try and use them as part of a query. So this: return _sessionFactory.GetCurrentSession().QueryOver<BoxMember>() .Where(x => x.Box.Id == boxId) .Where(x => x.Member.DeletedDate == null) .Fetch(x => x.Box).Eager .Fetch(x =

Subqueries with QueryOver

不打扰是莪最后的温柔 提交于 2019-12-06 10:34:31
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 by name and type as well as City which is in Address table Keith.Abramo Try something like this: Address