nhibernate

How can I handle a possibly empty parameter List when using a named query in NHibernate?

I'm having issues on handling a situation where a list of parameters sent to a named query in NHibernate is empty. This is an example of my situation: <sql-query name="MyClass_FilterByCategoryID"> <return alias="MyClass" class="MyProject.BusinessEntities.MyClassBE"/> <![CDATA[ SELECT DISTINCT MyClass.* FROM MyClassTable...

NHibernate with Inversion of Control

This is just something I've been thinking about and was wondering if it exists, or even if its beneficial at all. I'm doing inversion of control and dependency injection using Unity. I'm also doing ORM with fluent nHibernate. I was wondering if there was a way to either configure nHibernate to take interfaces as its type parameters an...

NHibernate + SqlDbType.Structured

Is it somehow possible to use SqlDbType.Structured in NHibernate ? Explanation: I want to pass collection of ids to stored procedure that will be mapped using nhibernate. This technique was introduced in Sql Server 2008 ( read ). I just don't want to pass (again) multiple ids as nvarchar and then chop in in sql server side. ...

NHibernate QueryOver<T> with Interfaces??

Hi, I have a repository object that knows the Type of the mapped hibernate class. But it doesn't have a generic <T> type but instead a reference to a Type object Type TheMappedType. So I cannot do something like: session.QueryOver<typeof(TheMappedType)>().... Usually what I can do with hibernate is: session.Get(typeof(TheMappedType), s...

How to store a non truncated varchar(max) string with NHibernate and Fluent NHibernate

My DB schema has a string as a varchar(max). I have read the other questions concerning setting Length to more than 4000 or 8000 so that it really generates a (n)varchar(max) in the mapping but when I use Length(10000) in my mapping class, the hbm file actually shows length="10000" and if I save an entity with more than 10000 chars, it i...

How can I map NHibernate domain classes with an existing table

Hi I am presently trying to use NHibernate on a project where I do not have permissions to CREATE TABLE in SQL 2005. I keep getting a mapping error, and my assumption is that I do not setup the table by generating it. Is it fair of me to assume that NHibernate can only map successfully with tables that were generated by its tool? If n...

Where to put business rules for querying when using NHibernate?

Still new to NHibernate. I'm using NHibernate 2.1.2 and the Linq provider. I am wondering where I should put my business rule logic. For example, I have an entity called Service with DateTime property. In my web app, I only ever want to display/work with services whose DataTime is less than 4 weeks away. Where should I put that rule? I...

How can I model this object hierarchy in Fluent NHibernate without violating DDD principles?

I am trying to build a domain model that will allow me to manage Contracts. The Contract class is my aggregate root, and it has a single property right now, which is Reviewers. Reviewers, in the context of the Contract, each have a property to it's parent Contract, and a First Name, Last Name, and Login. The reason they have these pro...

NHibernate: Querying with OR operator

I am looking for a way to build an OR operator into a query to look for a particular value in one field of a table as well as in another field of a joined table. This is pretty basic in SQL, but I can't for the world figure out how to do this in NHibernate. I have been searching the web, but the examples I find are pretty nebulous to me ...

Removing an item from a many-to-many association in NHibernate

Dearest All, I have a one-directional many-to-many association: the ListDefinition class has the Columns property of type IList, while a column can be part of several ListDefinition-s. The problem is, whenever I try to remove a column from one Columns collection (without deleting it or removing from other ListDefinitions), I'm getting t...

Filter using criteria on not mapped column

I have a entity mapped to a table and an extra column which is not mapped. Is it possible to make a select using criteria and filter on that extra column? ...

NHibernate: what's the differense between DetachedCriteria and ICriteria

this classes have some similar methods but seems to work slightly different. What's the difference of them and when should I use each of them? ...

ISession per Request (Only when necessary)

Hi Friends, I'm developing an application (asp.net mvc) and I'm using ISession per request (in globa.asax I use Bind and Unbind in Begin_Request event and End_Request event). Everything works fine but sometimes (some requests) I don't need to use an ISession (a connection with database). I'd like to know if is there any way to open an ...

NHibernate check for changed to prompt for save

I was wondering if there is any sort of functionality in NHibernate to check if changes have been made to an object sense it has been loaded that would require a write to the DB to save. I have some other pieces like currently selected elements and so forth that may change but if they do it makes no difference in terms of actual data. ...

NHibernate and INotifyPropertyChanged

I am having some issues with binding to objects retrieved from NHibernate using lazy loading. I have read some on the issue and am confused on what I need to do to fix things here. As I understand it the issue has to do with the way NHibernate handles the proxies for things that haven't been loaded yet. Has someone implemented NHibernat...

Fluent NHibernate and MySQL cast syntax?

I have a table in MySQL which has a string column 'Id' of the form "Xnnnn" where nnnn is a number. I want to find the largest nnnn defined. So I have: var c = s.CreateCriteria(typeof(Item)) .AddOrder(Order.Desc( Projections.Cast( NHibernateUtil.Int32, Projections.SqlFunction("substring", NHibernateUtil.String, ...

NHibernate mapping with forking inheritance model

I'm just starting out with NHibernate and am trying to do a mapping for my model. (this is a model-first, TDD approach, just creating the database now) My Class hierachy is something like : I'm trying to work out how to map this now using a mapping xml file? This is my table and what I want them to map to QuestionId - Int - [Quest...

Example of how to use active record with asp.net mvc

I am looking for the best approach to using NHibernate and MVC.net. I have gone through http://www.codeproject.com/KB/architecture/NHibernateArchitecture.aspx Someone has pointed to the use of Castle project Active record. My aim is to eliminate the need for any nhibernate dependencies within my domain. I want a quick and easy do...

NHibernate: returning List<EntityType> not List<Object[]> when using grouping

when using Nhiberante Criteria API or HQL with grouping, query returns list of arrays of entity properties List<Object[]> at which grouping was made. If I need to return only certain property how can I do that? preferably with Nhiberane API if possible ...

NHibernate's ICurrentSessionContext is being cleaned up

I have a Windows.Forms application and we need to use one session and keep it opened, because our application is a legacy product that we're moving to NH. Here is the code that gets a session: public static ISession GetCurrentSession() { ISession session; if ( CurrentSessionContext.HasBind( SessionFactory ) ) { ses...