I have a Person entity. Every person has a country, I want to select all the distinct countries that have people in them. This Criteria Query returns all the distinct CountryID's
criteria.SetProjection(Projections.Distinct(Projections.Property("Country")));
How do I alter it to join and fetch the Country entity, not just the ID?
...
Anyone know how to convert an ICriteria into a DetachedCriteria. I need to use an existing ICriteria as part of a subquery using:
.Add(Subqueries.PropertyIn("Name", myDetachedCriteriaSubquery))
Is there any way to convert an ICriteria to a DetachedCriteria. I will accept 'no' with a credible reference.
...
hi i am new in NHibernate and i am a little confused.
Suppose we have a product table.
Let the product table have 2 columns price1 and price2.
then i may query mapped product entities via HQL as follows:
string queryString = @"from product p
where p.price1 = p.price2 + 100 ";
IList result = session.CreateQuery(queryString).List();
...
I'm still quite new to NHibernate and most of it I'm getting to grips with. One area that I'm really lacking a proper understanding of though is querying (at least when it comes to anything reasonably complex).
I learn best by example, but I feel that I haven't really been able to find all that many in depth querying examples on the we...
My application creates a dynamically generated query at runtime based on user input by creating Criterion objects e.g:
ICriterion criterion = Restrictions.Eq("Name", "John");
......
detachedCriteriaSomewhereElse.Add(criterion);
How do I do this in NHLambdaExtensions?
what I really need to do is
ICriterion criterion = Restrictions.Eq...
Hello,
I have an NHibernate application that currently makes use of a SQL Server user-defined function. I would like to avoid having to call this function, and instead express its logic using the NH criteria API. Unfortunately, I'm having difficulty applying the criteria examples in the NH documentation to my particular case. So I'm tur...
I have a Class like below
public class Customer
{
public virtual int ID { get; set; }
public virtual IList<LokalPortalen.Domain.Entity.CustomerLocationType> CustomerLocationTypes { get; set; }
public virtual ZipCode ZipCode { get; set; }
public Customer()
{
CustomerLocationTypes = new List<LokalPortalen.Doma...
In a table that stores multiple rows per employee, I want to pull one row per employee that represents the most recent entry for each employee. Here's where I am with hand-written SQL:
SELECT [all the selected columns here]
FROM Nominations t
inner join
(select max(NominationId) mostRecentNominationId,
EmployeeId from Nomi...
I have to display some objects which are stored in a relational database and I use fluent NHibernate to get them.
Since I need paging, I have to get both - the count of all objects, and the objects for the current page themselves.
The ICriteria for both purposes is very similar up to a point - for count i finally add
.SetProjection(Pro...
Let's say I have a base class called Pet and two subclasses Cat and Dog that inherit Pet.
I simply map these to three tables Pet, Cat and Dog, where the Pet table contains the base class properties and the Cat and Dog tables contain a foreign key to the Pet table and any additional properties specific to a cat or dog. A joined subclass ...
Is there any way I can filter my NHibernate query on the SubType field before I hit the database by adding an ICriterion to my executing DetachedCriteria?
My code looks something like this:
DetachedCriteria detachedCriteria = DetachedCriteria.For(typeof(MyObject));
ProjectionList projectionList = Projections.ProjectionList();
...
I have a table with more than 10 000 000 rows.
In TOAD this query works very well on it:
select /*+ INDEX(x IDX_CASHFLOW_COMPLEX)*/ *
from MYPR.CASHFLOW x
where fk_debet in (21856, 21854, 21855)
IDX_CASHFLOW_COMPLEX is index on 5 columns created by following script:
CREATE INDEX MYPR.IDX_CASHFLOW_COMPLEX ON MYPR.CASHFLOW
(FK_DEBIT...
Say I have abstract base class Animal then Dog and Cat classes. I'm mapping these via table-per-subclass (w/ discriminator). Is it possible to query Animals and also project the discriminator-value or class name?
It seems I cannot project the discriminator column. I know when I list Animals, NHibernate creates the correct Animal type f...
I've managed to configure the L2 cache for Get\Load in FHN, but it's not working for queries configured using the ICriteria interface - it doesn't cache the results from these queries.
Does anyone know why?
The configurations are as follows:
ICriteria:
return unitOfWork
.CurrentSession
.CreateCriteria(typeof(Country)...
I am still new to Hibernate and am attempting to use it for a web site I have inherited. Unfortunately that means sometimes the db schemas don't always make sense.
With that said, I am trying to build the following HQL query using the Criteria API
from TableB b where b.id = :id and b.TableAProperty.UserId = :userId
The above HQL sta...
Please can someone explain in english what the following code does?
var subCriteria = DetachedCriteria.For<UserLocation>();
subCriteria.SetProjection(Projections.Property("LocationId"))
.Add(Restrictions.Eq("UserId", userId));
return UoW.Session.CreateCriteria(typeof(Location))
.Add(Subqueries.PropertyIn("LocationId"...
Hi,
In my system Users own 0 or more Categories. Here is a simplified version of my model classes:
public class User
{
public virtual String Name {get; set;}
public virtual IList<Category> Categories { get; set; }
}
public class Category
{
public virtual String Title {get; set;}
}
I now want to create an ICriteria query ...
This is the setup for my 2 entities:
public class Person {
public Guid Id {get;set;}
public string Name {get;set;}
}
public class Immortal : Person {
public string DarkName {get;set;}
}
Here's what their mapping looks like:
<class name="Person">
<id name="Id">
<generator class="guid.comb"/>
</id>
<property name="Name...
Let's say I have an entity called MyItem. It can be included in many "parents", like SomeCollection and SomeOtherCollection. Because it can be included in many parents, and since I don't want MyItem to know about the parents, I'd like to not have any properties in MyItem referencing a parent.
And since a parent, like SomeCollection, can...
Hi!
I want to create the following T-SQL statement:
SELECT SUM (sa.Amount) as 'SumAmount',
SUM(sa.Cost) as 'SumCost',
gg.[Description] as 'Goodsgroup', Month(sa.[Date]) as 'Month'
FROM SalesmanArticle sa
INNER JOIN Article a
ON a.ArticleId = sa.ArticleId
INNER JOIN GoodsGroup gg
ON gg.GoodsGroupId = a.GoodsGr...