queryover

NHibernate JoinAlias query with null test not working

…衆ロ難τιáo~ 提交于 2019-12-10 16:15:59
问题 I'm getting some unexpected behaviour with a JoinAlias QueryOver in NHibernate. My entity essentially looks like this: public class Field { public virtual long Id { get; protected set; } public virtual Field Parent { get; protected set; } public virtual FieldType Type { get; protected set; } public virtual string Value { get; protected set; } ...(Ctors etc } My mapping is such: public class FieldMap : ClassMap<Field> { public FieldMap() { Id(x => x.Id) .GeneratedBy.Native(); References(x => x

Queryover dynamic fetch with joins

点点圈 提交于 2019-12-10 10:37:28
问题 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

Dynamic sorting in NHibernate QueryOver using expressions

你离开我真会死。 提交于 2019-12-10 10:04:42
问题 Given the following QueryOver : UserProfile userProfileAlias = null; Pegfile pegfileAlias = null; var q = Session.QueryOver(() => pegfileAlias) .JoinAlias(() => pegfileAlias.UserProfile, () => userProfileAlias); I would like to make the following statement dynamic, by swapping q = q.OrderBy(() => userProfileAlias.Forename).Asc; (OrderBy(Expression<Func<object>> or ( OrderBy(Expression<Func<T, object>>) ) with q = q.OrderBy(GetMemberExpression(userProfileAlias, "Forename")).Asc; I borrowed

nhibernate queryover LIKE with expression trees

半世苍凉 提交于 2019-12-10 03:58:07
问题 I'm looking to add a method to my base repository class that allows me to use LIKE expressions but I'm not quite sure of how to go about this. I want to create a generic method that looks at the expression tree passed in and looks for wildcard characters in the string values passed in. It would then generate the QueryOver statement accordingly. I have the following currently: public IList<T> FindAll(Expression<Func<T, bool>> criteria, char wildCard) { return SessionFactory.GetCurrentSession()

Complex nHibernate QueryOver expression

岁酱吖の 提交于 2019-12-10 01:47:56
问题 I have the following objects in a hierarchy A > B > C > D . Each object is mapped to a table. I'm trying to write the following SQL using QueryOver: SELECT B FROM A, B, C, D WHERE A.ID = B.ID AND B.ID = C.ID AND C.ID = D.ID WHERE A.NUMBER = 'VALUE' AND D.NAME IN ('VALUE1', 'VALUE2') I have the C# code so far: string[] entityNames = entityAttributes.Select(e => e.Name).ToArray(); string customerNumber = 2; return session.QueryOver<B>() .JoinQueryOver(b => b.C) .JoinQueryOver(c => c.D)

Select or SelectList: I Want to include the entire entity

这一生的挚爱 提交于 2019-12-09 21:31:08
问题 I am querying a list of objects, and then correlating them with a subquery. I want to return the results of the subquery, as well as the root entity. But I can't figure out how to actually return the root entity, I can only return individual properties of it. Specifically, this works: this.Session.QueryOver<MediaFile>(() => mediaFile) .SelectList(list => list.Select(mf => mf.Id)); But this does not: this.Session.QueryOver<MediaFile>(() => mediaFile) .SelectList(list => list.Select(mf => mf));

nhibernate - queryover - how to make dynamic sorting for joined queries

送分小仙女□ 提交于 2019-12-09 20:05:48
问题 I have a user accounts table in admin panel and this table holds data from different db tables (tables in SQL database ). And user accounts table has to support paging and sorting. When I try to sort data with "FirstName" fetched from Account db table , .net throw an exception saying Location db table does not have "FirstName" column. My method is like: Account acc = null; //bunu bu şekilde tanımlamadan olmuyor :S AccountLogin accl = null; //bunu bu şekilde tanımlamadan olmuyor :S Program

GROUP BY and HAVING clauses in nHibernate QueryOver

吃可爱长大的小学妹 提交于 2019-12-09 16:24:28
问题 I'm trying to write this specific sql query in nHibernate QueryOver language, which I am not very familiar with: SELECT MessageThreadId FROM MessageThreadAccesses WHERE ProfileId IN (arr) GROUP BY MessageThreadId HAVING COUNT(MessageThreadId) = arr.Count where arr is a array of integers(user Ids) I'm passing as argument and MessageThreadAccess entity looks like this: public virtual MessageThread MessageThread { get; set; } public virtual Profile Profile { get; set; } .... After reading

QueryOver API OrderBy using Case

荒凉一梦 提交于 2019-12-09 15:55:48
问题 How can I perform the following LINQ to NHibernate query using the QueryOver API. This gets a list of all records of Item from the DB and places Items with the status "Returned" to the end of the list. The status is an Enum which is mapped to a nvarchar in the database. var workList = session.Query<Item>() .OrderBy(i=> i.Status == Status.Returned ? 1 : 0) .ToList(); The SQL equivalent is SELECT * FROM Item ORDER BY case when Status='Returned' then 1 else 0 end I've of course tried var

Using NHibernate QueryOver with a complex scenario

…衆ロ難τιáo~ 提交于 2019-12-09 14:05:58
问题 I´m trying to use QueryOver in that scenario : public class Class1 { public virtual string Name { get; set; } public virtual string Descripton { get; set; } public virtual Class2 { get; set; } public virtual IList<Class3> ListClass3{ get; set; } ... //SEVERAL OTHERS LISTS, PROPERTIES } public class Class2 { public virtual string Name { get; set; } ... //SEVERAL OTHERS LISTS, PROPERTIES } public class Class3 { public virtual string Name { get; set; } public virtual Class4 { get; set; } ... /