I have a simple test object model in which there are schools
schools have a collection of students.
I would like to retrive a school and all its students who are above a certain age.
I carry out the following query in the following manner :
public School GetSchoolAndStudentsWithDOBAbove(int schoolid, DateTime dob)
{
va...
I'd like to sort my result like this:
First I want all rows/objects where a column/property is not null, then all where the colmn/property is null.
Then I want to sort by another column/property.
How can I do this with ICriteria? Do I have to create my own Order class, or can it be done with existing code?
ICriteria criteria = Sessi...
I´m having some trouble retrieving a collection of strings in a projection:
say that I have the following classes
public class WorkSet {
public Guid Id { get; set; }
public string Title { get; set; }
public ISet<string> PartTitles { get; protected set; }
}
public class Work {
public Guid Id { get; set; }
public WorkS...
I have an answered StackOverflow question about how to combine to legacy CHAR database date and time fields into one .NET DateTime property in my POCO
here (thanks much Berryl!). Now i am trying to get a custom ICritera query to work against that very DateTime property to no avail. here's my query:
ICriteria criteria =
Session.Cr...
I am using NHibernate, and am trying to figure out how to write a query, that searchs all the names of my entities,
and lists the results. As a simple example, I have the following objects;
public class Cat {
public string name {get; set;}
}
public class Dog {
public string name {get; set;}
}
public class Owner {
public string...
I am creating a method that can create filter understood by NHibernate (by filter i mean a set of ICriteria object for example) from my abstract filter object.
public static IEnumerable<ICriterion> ToNhCriteria(this MyCriteria criteria)
{
// T4 generated function
// lots of result.Add(Expression.Or(Expression.Eq(),Expression.Eq)) ...
public class Entity
{
public virtual string Title { get; set; }
public virtual DateTime CreationDate { get; set; }
public virtual int Count { get; set; }
}
I have a problem when creating Criteria for a given entity:
var s = session.CreateCriteria<Entity>()
.Add(Expression.Ge("CreationD...
I have a schedule (Voyages) table like this:
ID Arrival Departure OrderIndex
1 01/01/1753 02/10/2009 0
1 02/11/2009 02/15/2009 1
1 02/16/2009 02/19/2009 2
1 02/21/2009 01/01/1753 3
2 01/01/1753 03/01/2009 0
2 03/04/2009 03/07/2009 ...
I write same query with two approach by using NHibernate:
1- by using HQL like below
public long RetrieveHQLCount<T>(string propertyName, object propertyValue)
{
using (ISession session = m_SessionFactory.OpenSession())
{
long r = Convert.ToInt64(session.CreateQuery("select count(o) from " + typeof(T).Name + " as o" + "...
I have a very simple class:
class Product
{
public virtual int ID { get;set;}
public virtual Categori MainCategori { get;set;}
}
i would like to make a "Select Count(ID),MainCategori From Products Group By MainCategori" by Using ICriteria. My code is like follows
using (var sessionFactory = C...
I have a person object, which can have unlimited number of first names. So the first names are another object.
ie
person --- name
--- name
--- name
What I want to do is write an nhiberate query using which will get me a person who has certain names.
so one query might be find someone whose names ar...
How should I go about writing a backwards like statement using NHibernate criteria?
WHERE 'somestring' LIKE [Property] + '%'
Sub Question:
Can you access the abstract root alias in a SQLCriterion expression?
This is somewhat achievable using the SQLCriterion expression
Expression.Sql("? like {alias}.[Property] + '.%'", value, NHi...
I needed to filter a list of results using the combination of two properties. A plain SQL statement would look like this:
SELECT TOP 10 *
FROM Person
WHERE FirstName + ' ' + LastName LIKE '%' + @Term + '%'
The ICriteria in NHibernate that I ended up using was:
ICriteria criteria = Session.CreateCriteria(typeof(Person));
criteria.Add(...
Assuming the following fictional layout
Dealership
has many Cars
has a Manufacturer
I want to write a query that says get me a Dealership with a Name of X and also get the Cars collection but use a join against the manufacturer when you do so. I think this would require usage of ICriteria. I'm thinking something like this..
...
It looks like this question: NHibernate.Linq and MultiCriteria provides a potential way to combine using Linq to NHibernate and ICriteria together in the same query (in my case, to add fulltext search predicates to Linq to NH queries).
If you wrapped the Linq to NHibernate IQueryable<T> with your own implementation, you could even inc...
Hello everyone!
I'm making a query that sorts and returns X rows based on row_number()
I'm using NHibernate with MSSQL and im trying to get paging working using CreateSQLQuery and i have this query:
select s.*
from(
select distinct release.[stop], survey.SurveyId, survey.Created, survey.CopyOfId, survey.DesignTemplateId, survey.Us...
I have a list of NHibernate.Expression.Order objects and want to convert them into a sql string.
i.e. "Name ASC, Id DESC, Amount ASC"
...
I have the following two entities:
public class Entity1
{
public IList e2 { get; set; }
}
public class Entity2
{
public string Title { get; set; }
}
I only have repository for Entity1, I know I can do a LIKE query with the following criteria:
criteria.CreateAlias("e2", "e1e2").Add(Restrictions.LIKE("Title", "needle", Match.Anyw...
Hi,
What are the performance differences between the hql and criteriaApi and QueryOver? Are there any situations where one is faster or slower than the other?
Edit: I extended the question with QueryOver.
=============================================
Well, I am not sure which response to mark as answer so I will mark posts with most ...
Hi all,
Using NHibernate I'm trying to get obtain a list of B's where an IList property of B contains a specific instance of A.
The following code should hopefully explain the situation more clearly:
public void test()
{
A a1 = new A();
A a2 = new A();
B b1 = new B();
b1.As = new List<A> { a1 };
// ...database save...