I need to replicate the following working HQL query using criteria API.
session.CreateQuery(
"select c " +
"from Parent p " +
"inner join p.Children c " +
"where p.Id = 9 " +
"and c.Id = 33")
.SetMaxResults(3)
.List();
The query selects all the children that satisfy a certain criteria that belong to parents...
Hi I want to write a FindByExample(object o) method. So I tried this:
public IList<T> FindByExample(T o)
{
return Session.CreateCriteria(typeof(T)).Add(Example.Create(o)).List<T>();
}
(It's in a generic class)
It should work fine, but if T has a property of an enum type, it throws this exception:
"Type mismatch in NHibernate.Cri...
Hello there, Im having a problem creating a projection for my nhibernate detachedcriteria object.
I have a class Spa which is linked to table Address.
Address has a field called City which is a string.
public class Spa : IAggregateRoot
{
[BelongsTo("AddressID", Cascade = CascadeEnum.All)]
public Address Address { ge...
Hi,
Assuming the following scenario:
class Project{
public Job Job;
}
class Job{
public Name;
}
Assuming I want to use the Criteria API to search for all projects whose Job has the name "sumthing".
I could use the CreateAlias to create an alias for Job and use it to access Name, or I could create a new Criteria for the proper...
Hi,
I use CTE to handle paging of data currently, can criteria queries handle CTE?
...
how can we get distinct result by using criteria in hibernate.
...
I have multiple services which call on my database service, which uses Hibernate, and I would like the remote services to be able to create a query and then pass that to be processes. Ideally I would like to pass a Criteria Object but it looks like it needs a Session which they won't have access to. Is there a process similar to the Crit...
In nhibernate, I have two classes that are associated with a many-to-one mapping:
<class name="Employee" table="Employee">
..
<bag name="orgUnits">
<key column="id" />
<one-to-many name="OrgUnit" class="OrgUnit">
</bag>
..
</class>
I would like to use a criteria expression to get only Employees where the the collection...
Here are my relevant classes:
public class Item {
public virtual int Id { get; protected set; }
public virtual IList<Tag> Tags { get; set; }
}
public class Tags {
public virtual int Id { get; protected set; }
public virtual string Name { get; set; }
public virtual IList<Item> Items { get; set; }
}
These are mapped...
I'm really new with Hibernate. I want a List<User> using hibernate criteria, but only with fields User id and name filled up. Is that possible? Something like the query shown below:
SELECT user.id, user.name FROM user
Regards.
...
Hi,
In HQL I can do something like this:
select roleHeldByOwner.TargetPerson
from Person roleOwner
join roleOwner.RolesOnPeople roleHeldByOwner
where roleOwner.Id = :roleOwnerId
How can I achieve the same thing in a Criteria query? Specifically the selecting of something that isn't the first entity in the From clause.
Thanks,
Matt
...
I have an Ms Access view(query) as following
select * from employee Where EmployeeId=SomeID
Here SomeId is not a field name
If I run this query from MsAccess
It prompts me for entering value for SomeId as follows
|---------------------------------------|
| Enter Parameter Value X |
|-----------------------------------...
I'm trying to filter by a list of values using the criteria API. I suspect that this is not possible, I'm just asking here to be sure.
class Entity
{
int id { get; set; }
IList<Guid> Guids { get; set; }
}
The mapping:
<class name="Entity">
<id ...></id>
<bag name="Guids" table="Entity_Guids">
<key column="Entity_FK"/>
...
Hi,
small questions about Restrictions.or and Restrictions.and
If I do something like this:
...
criterion = criterionA;
criterion = Restrictions.and(criterion, criterionB);
criterion = Restrictions.or(criterion, criterionC);
criterion = Restrictions.and(criterion, criterionD);
Will this be treated as:
(A and B) or (C and D) (follow...
Hi
I have this query:
criteria = session.CreateCriteria(typeof (Building))
.CreateAlias("Estate", "estate")
.SetProjection(Projections.ProjectionList()
.Add(Property.ForName("Name"), "BuildingName")
.Add(Property.ForName("estate.Name"), "EstateName")
.Add(Proj...
I have a hibernate mapping which looks like this:
<hibernate-mapping>
<class name="MutableEvent" table="events"
mutable="true" dynamic-insert="true" dynamic-update="true">
<id name="id">
<generator class="assigned" />
</id>
<property name="sourceTimestamp" />
<property name="entry...
Update
I've been looking around the NHibernate.Search.Tests project to find out how the Criteria API is used (i find it immensely useful to look around the test code to have working examples) and i noticed that the way to use the Fulltext search is radically different. Here are two tests, one with the criteria API, one with the classic ...
Hi!
I would like to make a query which needs to compare an property's property with some value. For example:
... WHERE Identity.Location.Room = "room #1"
How can I achieve this with criteria api?
Best RegardsOliver Hanappi
...
enter code hereI want to apply restrictions on the list of items, so only items from a given dates will be retrieved.
Here are my mappings:
<class name="MyClass"
table="MyTable" mutable="false" >
<cache usage="read-only"/>
<id name="myId" column="myId" type="integer"/>
<property name="myProp" type="...
Hi,
I tried to query a table using hibernate. In criteria how to apply mathematical operations in two column values?
...