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.
...
Inspired by the DDD hype, I designed my classes pretending there was no database at all. And then used NHibernate to map the classes to database tables. Part of my class graph look like this: Order (hasmany)--> Product (belongsto)-->Seller. To retrieve all orders placed for a certain seller. I have the code:
public class Order:ActiveRec...
I'm using return Json(whatever); inside an ASP.NET MVC Action to return data to my page via JSON. I'm using jQuery to perform the JSON request and subsequent interaction with DOM.
when whatever contains NHibernate objects with collection members (i.e. contains ISet objects), the callback function is never invoked by jQuery.
We're using...
Have a look at the following tests:
[TestMethod]
public void CanRead()
{
using (ISession session = OpenSession())
{
var criteria = session.CreateCriteria(typeof(Action));
var result = criteria.List<Action>();
Assert.IsTrue(result.Count > 0);
}
}
[TestMethod]
public void CanReadWithLinq()
{
using (ISession...
I want to auto generate .hbm mapping files from my domain objects
...
I have the following model which I have created and mapped with nHibernate.
Using lazy loading so I don't need to get the Vehicles for the Dealer at the start.
Public class Dealer
{
public virtual string Name { get;set;}
public virtual IList Vehicles { get;set;}
}
Now lets assume the Dealer has thousands of vehicles.
If I do Dealer.Ve...
If you have the tables Groups, Users, Channels and between each two a linktable, how do you organize that in Domain Driven Design and nHibernate? Does a Group have a UserCollection and a ChannelCollection, a User a GroupCollection and ChannelCollection and a Channel a GroupCollection and UserCollection?
And if you want to add a Group to...
I have three classes-- User, Team, and ProjectBid. Both User and Team inherit from a IProjectBidder interface. I want to map them in ActiveRecord something like this:
class Team: ModelBase<Team>, IProjectBidder
{
[HasMany(typeof(ProjectBid), Table = "ProjectBid", ColumnKey = "BidderID", Lazy = true)]
public IList<P...
Dear ladies and sirs.
My question is simple, given an ID (and the object type, of course) what is the best way to check whether this ID is present in the database using NHibernate?
Thanks.
...
I use linq to nhibernate and the IQueryable.Where function in an application I'm building. And what mystifies me is how do the Expressions I create and pass to the Where function of a INhibernateQueryable affect performance.
I'm not really sure what are the gotchas I should avoid in writing these query Expressions, in terms of perfor...
I'm using Compare .NET Objects to test whether my POCOs are persisted correctly to a test database. Let's take an example POCO:
public class NoahsArk
{
public virtual Noah Noah { get; set; }
}
And the mapping file, using FNH:
public class NoahsArkMap : ClassMap<NoahsArk>
{
References(x => x.Noah).Cascade.All();
}
Now, I run...
I've formerly used L2S and am looking at using NHib along with the Sharp Architecture on a project. I've started prototyping and come up against the first issue which i have no idea how to google for.
Given a POCO with some simple properties, and one reference property (Category - class not shown here):
public class Post
{
public Pos...
I am trying to use NHibernate with legacy entities that are not mapped with NHibernate. On occaisson this means that I need to manually flush NHibernate data to the database so that I don't receive foreign key exceptions when I try to connect the legacy entities with NHibernate-mapped entities.
A problem occurs when this takes place wit...
Dear ladies and sirs.
I have the following code snippet:
using (var scope = DataAccessPortal.DataContext(DB.Main).OpenStatementScope())
using (var transaction = scope.BeginTransaction())
{
// Several other database operations.
if (scope.ExistsById(obj.GetType(), obj.Id))
{
scope.Update(obj);
}
else
{
scope.Insert(ob...
I have a filter like this:
<filter name="partnerIdFilter" condition="partner_id IN (:partnerId)"/>
and the partnerId parameter is defined like this:
<filter-def name="partnerIdFilter">
<filter-param name="partnerId" type="int[]"/>
</filter-def>
and the filter is enabled like this:
currentSession.EnableFilter("partnerIdFilt...
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();
...
Is it possible to filter on a particular joined-subclass in NHibernate?
For example, I have the following classes:
Pet { Name }
Cat: Pet { Paws }
Budgie: Pet { Wings }
Person { Pets }
I want to create an NHibernate search to give me Persons with Cats with 4 paws.
I can only seem to be able to restrict on a Pet's attributes (Name)......
I want to be flexible even after deploying my code so I like to use the hibernate.cfg.xml file for configuring NHibernate. Now, I am planning to use Fluent NHibernate to do all my Class => Table mapping. Is there a way I could use the old NHibernate Configuration class to configure Fluent NHibernate?
...
Dear ladies and sirs.
I use NHibernate as my DAL. My objects are versioned. I have noticed that when I save an object, NHibernate sets the mapped properties again. It all starts in the AbstractSaveEventListener.PerformSaveOrReplicate method, which decides to "substitute" the values.
Anyway, here is the stack trace:
NHibernate.dll!NHib...