nhibernate

Entity Framework success stories?

So like many developers before me, I am at the crossroads of choosing an ORM to learn thoroughly and move forward with for future projects. I have been playing with Entity Framework and so far like what I see, although I have only tried simple things, CRUD with clearly defined table relationships with a 1-1 table-entity mapping. I did so...

NHibernate HQL logic problem

Hi I'm trying to write an NHibernate HQL query that makes use of parenthesis in the where clause. However, the HQL parser seems to be ignoring my parenthesis, thus changing the meaning of my statement. Can anyone shed any light on the matter? The following HQL query: from WebUser u left join fetch u.WebUserProfile left join fetch...

Plain SQL output from NHibernate

I need: Plain SQL that I can run without modification with sqlcmd.exe to insert testdata into testdatabase. I have: Service calls and entities to generate the insert operations with NHibernate. Not working solution: Log output to text-file. NHibernate generates parameterized sql but logs them in a format not runnable by sqlcmd.exe. ...

Fluent nHibernate no identity column in table...

How do I specify with fluent nHbiernate mapping for a table that doesn't have an identity column? I want something like this: public sealed class CustomerNewMap : ClassMap<CustomerNew>, IMap { public CustomerNewMap() { WithTable("customers_NEW"); Not.LazyLoad(); Not.Id(); // this is invalid... Ma...

NHibernate - problems with validation and transactions

I'm using NHibernate as my ORM. I have a situation where I have some stuff wrapped in an ITransaction. I am listening to the SaveUpdate event in NHibernate and then doing my entity validation in that SaveUpdate handler. For one of my entities, I want to validate that the value of a certain property hasn't changed. So I figured that I...

How do I configure my nhibernate project to use memcached in the hibernate.cfg.xml?

I am trying to configure the hibernate.cfg.xml file to use memcache. I see the properties "cache.provider_class" and "cache.use_second_level_cache" however I do not see how I can add the server host/port. ...

Parameters substitution not working

Hi All, In my config i have this: 'English (United States)' 1, 'Español (España)' 2 I'm executing a stored procedure that expect an int. I'm getting the exception: '...cannot convert nvarchar to int...' . Tha is because the substitution is not working. I never get 'English (United States)'replaced with 1 I'm doing parameter bindi...

What is the best approach to make data access methods in NHibernate?

For example, I have two classes: Foo and Bar. This classes are mapped to some tables. As for now, I have static methods for each class: Add, Update, Delete, Get. E.g.: public class Foo { private Guid _id; private string _someProperty; static Foo Get(Guid id); static void Add(Foo foo); static void Update(Foo foo); s...

Problem with nhibernate, Mysql, and Guids

I have a view that flattens out a hierachy of 4 tables to display as a report. within the view it contains the primary keys (Guid) of each of the tables along with some display data. The problem is that the the guids are being returned as varbinary(16) instead of binary(16) and as a result nhibernate throws an error. This would appear...

Is there a difference between Binary(16) and VarBinary(16) in MySQL

Nhibernate seems to have a problem with varbinary(16) when tring to represent Guids. I would have thought that varbinary(16) and binary(16) equate to the same thing. ...

Is this session provider correct for the web?

Hi, Just learning nhibernate with fluent, and my session provider looks like: public class SessionProvider { private static ISessionFactory sessionFactory; public static ISessionFactory SessionFactory { get { if (sessionFactory == null) { ...

Creating an Update method in my nHibernate repository

Hi, My current repository looks like: public class Repository<T> : IRepository<T> { public ISession Session { get { return SessionProvider.GetSession(); } } public T GetById(int id) { return Session.Get<T>(id); } ...

How is Command Query Separation (CQS) implemented when using an ORM?

The principle behind the CQS architectural pattern is that you separate your queries and commands into distinct paths. Ideally, your persistence store can be read/write partitioned, but in my case, there is a single, normalized database. If you are using an ORM (NHibernate in my case), it's clear that the ORM is used when issuing comma...

Ninject and Singleton

My application uses NHibernate with a session per request implementation. I have a core library that provides a thread safe singleton for getting access to the current nhibernate session. That singleton is leveraged from the web application in the BeginRequest and EndRequest events to ensure the opening and closing of the session wit...

NHibernate Mapping Many-To-Many Relationship

I am having trouble mapping the many to many relationship! I have a Users table, Roles table and UserRoles table. A user can have many roles. The Roles table just store the name of the roles like Admin, Editor etc. The Userroles table stores the relationship of user with the roles. When I save the user the user information is saved but...

Bidirectional HQL Query with NHibernate

I'm fairly new to HQL / NHibernate so this may be a bit of an amateurish question. Basically I have a bidirectional many-to-one association. In my query, I am trying to find all of the “parent” entities that contain “children” that match a certain criteria. I really don’t want to run the first query on the children and then query the p...

Using nHibernate and the repository pattern, need some direction

Hi, Ok so I 'm just getting into nhibernate (using fluent). One thing that I love about it is that I can use the Repository pattern (read about it from the nhibernate rhino blog). Basically using generics, I can create methods that will work accross ALL my database tables. public interface IRepository<T> { T GetById(int ...

Injecting ISession Into My Repositories Using Structuremap in a Asp.Net MVC Application

My repositories all take ISession in the constructor: protected Repository(ISession session) { this.session = session; } private readonly ISession session; In an Asp.Net MVC application, using StructureMap, how would I go about setting up ISession in my the StructureMap Registry? Would I need to to add SessionFactory to the conta...

Using NHibernate IPreInsertEventListener and trying to find the mapped table

I'm attempting to implement a PreInsertEvent listener using the latest version of NHibernate. One of the things I want to do with in this listener is find the database table that my entity is going to be mapped too. (Assuming that it is only one table). Does anyone know where in the IEntityPersister I might be able to find this? ...

Fluent Nhibernate: Can't create database connection to MySQL

I have been looking into Fluent Nhibernate, and it seems really promising. But... I can't seem to get it working with a MySQL database. I have the Fluent Nhibernate example project running fine with the SQLite database (Fluent NHibernate: Getting Started), but as soon as I change the database configuration to this: return F...