nhibernate

NHibernate. Is there something like "CreateMultiSQLQuery" for batch SQL Statements

I am using CreateSQLQuery to retrieve some entities with complex criteria and everything works fine with entity retrieval. But I want at the same query to use a Batch of SQL statements having the same result as this HQL Query (Want to make some record Counts) : IList results = s.CreateMultiQuery() .Add("from Item i where i.Id > :id")...

Linq-to-NHibernate OrderBy Not Working

I'm trying order a Linq to NHibernate query by the sum of it's children. session.Linq<Parent>().OrderBy( p => p.Children.Sum( c => c.SomeNumber ) ).ToList() This does not seem to work. When looking at NHProf, I can see that it is ordering by Parent.Id. I figured that maybe it was returning the results and ordering them outside of SQL,...

What tools are available to auto-generate ASP.NET MVC REST services from domain objects?

I am developing an application for which I want to expose the basic CRUD operations on most of the database entities through REST web services. A colleague has demonstrated some impressive code generation using Grails. I would like to be able to generate my REST services as well, but using ASP.NET MVC instead of Grails. I planning on u...

Should NHibernate assign id to entities or should it be handled by application?

Hi I'm writing an application and started to test my domain model entities. If I Create an instance of entity Company like this var company = new Company("my company"); I should get a valid entity, meaning the company should at this moment have an Id correct? So the problem is that at the moment I have the Id generation made in the DB ...

Rolling back identifiers NHibernate

I would like to get NHibernate to roll back the identifier of any entities saved during a transaction if the transaction is aborted. I am using NHibernate 2.1.0, and it doesn't do this by default. I came up with the following solution, which works up to a point: public class RevertIdentifiersEventListener : DefaultSaveEventListener { ...

Is there a way to define reusable properties to n-hibernate mappings?

I have a scenario that i want to add some standard properties to my entities. Meaning that i will have e.g. 1 int and 2 string properties applied to all relevant entities. I have over 100 mapping files and most but not all will be hosts to these new properties. In the classes its easy to define this; in the mappings however i've found no...

Using NHibernate with ancient database with some "dynamic" tables

I have a legacy database with a pretty evil design that I need to write some applications for. I am not allowed to touch the database design at all, seeing how this is a fragile old system held together by spit and prayers. I am of course very aware that this is not how the database should have been designed in the first place, but real ...

NHibernate - Why my DateTime property is always DateTime.MinValue

Hello there, I have a [DataContract] called ReportRequest with a NOT NULL column 'SubmittedAt'. So my DataContract looks something like: [DataContract] public class ReportRequest { Int32 templateId; DateTime submittedAt = DateTime.Now; [DataMember] public virtual Int32? Id { get; set; } pu...

Verifying contents of NHibernate Criteria

I'm looking to build complex queries using the NHibernate Criteria API. I'd like to verify that the criteria is constructed as I would expect without having to actually run the query. Is this possible? Are there any tips or techniques for doing it elegantly? ...

Getting NHibernate to generate a HiLo string ID

Hi, We've got a large system that's loosely bound to its data source (Navision) via Unity - we're getting the opportunity to swap it out and have our own database. So we've had a look around and really like the look of Fluent NHibernate - we're trying to get a proof of concept going and swap out a couple of the services. We want to us...

Nhibernate Bag - Custom Loader Stored Procedure, Passing SQL Parameters

I am trying to create a custom loader for a bag that I have on an Nhibernate object using SQL 2005 stored procedure. Both the parent object and the objects in the bag are loaded using stored procedures (they don't map to actual tables). The problem I have is that I need to be able to pass parameters into the loader for the bag. The pa...

NHibernate - Why does Delete() call fail to delete but delete through HQL works?

Considering the following code blocks, why does call to HQL work but call to delete() not work? As a background, I'm using NHibernate over IBM.Data.DB2.Iseries driver. Come to find out, journaling on the AS400 is turned off so I can't use transactions. I'm not the AS400 admin or know anything about it so I don't know if having journaling...

Linq for NHibernate - filtering on <many-to-one> foreign key causes extra lookup

Trying out Linq for NHibernate and first noticed this: var list1 = (from ut in session.Linq<UserThings>() where ut.User.ID == 10 select ut).ToList(); var list2 = session.CreateCriteria(typeof (UserThings), "ut") .Add(Expression.Eq("ut.User.ID", 10)) .List<UserThings>(); This first query will join on the 'User' ...

NHibernate Aggregate Subquery

Hi all, I have a problem with NHibernate that I don't seem to be able to find a simple way around. I have the following database: Game: ID, Score, Match_ID Match: ID A match consists of 3 games. I want to find out what the maximum Match score is, so the following SQL would do the trick: select max(a.total) from (select Match.ID...

Linq to NHibernate projections? AliasToBeanTransformer?

Is there any way, using NHibernate 2.1 and Linq to Nhibernate 1.0, to use projections? Something like AliasToBeanTransformer in a criteria query? ...

Using Nunit to test constructor

Hello, I'm new to Nunit testing and I wanted to test the following constructor: public class IngredientDAONHibernate : NutritionLibrary.DAO.IngredientDAO { private Configuration config; private ISessionFactory factory; public IngredientDAONHibernate() { try { ...

How to test Nhibernate with Nunit?

Sorry for the repost. I'm using Nhibernate for ORM and have this class I need to perform unit tests using Nunit: using System; using System.Collections.Generic; using System.Linq; using System.Text; using NHibernate; using NHibernate.Cfg; using NutritionLibrary.Entity; using System.Data; using System.Data.SqlClient; using System.Collec...

How to use SetString parameter in Nhibernate 2.0.1

Hi Guys, I am in trouble right now. I am new in Nhibernate 2.0.1 Please see my code below. string strquery = "from MAgency ma where ma.statusflag= :statusflag"; IList magencylist = session.CreateQuery(strquery).SetString("statusflag", "1"). List(); No error found but there is no result entity coun...

How to insert data in an many-to-many Association table using NHibernate

Hi, I have 2 tables in database. Formula and Ingredient. They have many-to-many relationship, so I have an association table in the db thats called FormulaIngredient. I am using C#.net and SQL server 2005. My FormulaIngredient table has ID, formulaID, ingredientID, ingredientAmount. For this extra ingredientAmount field I created a a...

Ordered many-to-many relationship in NHibernate

Let's say I have two classes: Item and ItemCollection, where ItemCollection contains an ordered list of Item objects with an index, i.e. the list is ordered in a way specified by the user. Let's also say that they have a many-to-many relationship, an ItemCollection can contain many items and an Item can belong to several ItemCollections...