I have a simple one to many association in my model. The parent class has a collection of children. In the mapping files, the association is a one to many, eager-loaded, using fetchmode.join. This works fine, but how can I write a criteria query but NOT trigger the loading of the child collection? In other words, I want to query the pare...
I'm trying to use nhibernate's query by example to build dynamic queries. I'm stuck on how to code for an example object with multiple associations. Here's an example from NHibernate in Action. Its a 'User' object with a property 'Items'.
Example exampleUser =
Example.Create(u).IgnoreCase().EnableLike(MatchMode.Anywhere);
Example e...
Hi,Guys,i have a question about Criteria method,one-to-many relation to the database,'one' is "account",'many' is "sites",when i use CreateCriteria(),something appears let me in trouble.
Like this:"SessionFactory.OpenSession().CreateCriteria(typeof(Account)).List().Count();"
before it's run,i think the sql should be "Select count(*) f...
Lets say I have the following mapping:
<hibernate-mapping package="mypackage">
<class name="User" table="user">
<id name="id" column="id">
<generator class="native"></generator>
</id>
<property name="name" />
<property name="age" />
</class>
</hibernate-mapping>
Is it possible to select the oldest user (that i...
How to convert the following hql to Criteria API
var criteria = this.Session.CreateQuery("select m, m.Attachments.size from AdvanceMessage m");
?
Thanks
...
let's say I have 2 tables
table1(a,b) and table2(c,a)
I need to do something like this, but with NHibernate criteria:
select a,b, (select count(*) from table2 t2 where t1.a = t2.a ) x from table1 t1
anybody knows how to do this ?
...
I'm implementing an ingredient text search, for adding ingredients to a recipe. I've currently got a full text index on the ingredient name, which is stored in a single text field, like so:
"Sauce, tomato, lite, Heinz"
I've found that because there are a lot of ingredients with very similar names in the database, simply sorting by rele...
The code we're using is straight-forward in this part of the search query:
myCriteria.Add(
Expression.InsensitiveLike("Code", itemCode, MatchMode.Anywhere));
and this works fine in a production environment.
The issue is that one of our clients has item codes that contain % symbols which this query needs to match. The resulting SQL...
This is my problem, I have to use a big SP, and there is no time to rewrite in java.
So I'm using Hibernate criteria and I don't know if i can call it. Thanks to all.
...
I have a class Person who has a set of Books. It is not meaningful in the particular case to have an ordered or sorted collection.
Say now that I have a search page with a table showing the join of Person and Book. I want to be able to sort the results by fields from both Person AND Book, and then get a List from Hibernate, and iterate ...
I have entities similar to:
ProductLine: id, name
ProductLineContents: content_id, product_line_id
Content: id, text, updated_time
What I'd like to do is: for each product line, get the latest content (so if theres two content entries associated to one product line, the latest updated_time is rturned, and if one content item is associ...
I'm constructing a Hibernate Criterion, using a subselect as follows
DetachedCriteria subselect =
DetachedCriteria.forClass(NhmCode.class, "sub"); // the subselect selecting the maximum 'validFrom'
subselect.add(Restrictions.le("validFrom", new Date())); // it should be in the past (null needs handling here)
subselect.add(Property.f...
Currently our queries add a variety of Restrictions to ensure the results are considered active or live. These Restrictions are used in several places/queries so a method was setup similar to
public Criteria addStandardCriteria(Criteria criteria, ...) {
// Add restrictions, create aliases based on parameters
// and othe...
I'm running into an issue with adding JOIN's to a subquery using DetachedCriteria. The code looks roughly like this:
Criteria criteria = createCacheableCriteria(ProductLine.class, "productLine");
criteria.add(Expression.eq("productLine.active", "Y"));
DetachedCriteria subCriteria = DetachedCriteria.forClass(Model.class, "model");
subCr...
We are heavy users of the Hibernate Statistics in our application, but recently came to realize that Statistics.getQueries() does not return any Criteria queries. I realize that the method returns the HQL strings, but it also means that the Statistics are incomplete. I found a few older issues talking about this, but no resolution.
http...
For a column of type varchar I could write such a query:
public IList<Order> GetByName(string orderName)
{
using (ISession session = NHibernateHelper.OpenSession())
{
return session.CreateCriteria<Order>().
Add(Restrictions.Like("Name", string.Format("%{0}%", orderName))).
List<Order>();
}
}
How do I write a similar LIKE-qu...
Can I perform a Criteria query with Sub-Select AND Left-Outer join?
For example, I have A 1-many B 1-many C.
With Criteria.createAlias ("b", "b", Criteria.LEFT_JOIN) I can perform Left Outer join.
With Criteria.setFetchMode ("b", org.hibernate.FetchMode.DEFAULT) I can perform Join with the default fetching strategy. I assume that hav...
What is the best way to design a system where users can create their own criterias to search data ? By "design" i mean, data storage, data access layer and search structure.
We will actually refactor an existing application which is written in C# and ASP .NET and we don't want to change the infrastructure. Our main issue is performance ...
I have a method that returns a resource fully hydrated when the db is SQLite but when the identical code is used by SqlServer the object is not fully hydrated. I'll explain that with the code after some brief background.
I my domain various otherwise unrelated things like an Employee or a Machine can be used as a Resource that can be al...
I need a generic Criterion which forces the result to zero matches.
Something like Restrictions.eq(true, false) ?
...