nhibernate

How do I query through a many-to-many relationship using NHibernate Criteria and Lambda Extensions?

In my database I have a Person table and an Event table (parties, meetings, &c.). This many-to-many relationship is represented through an Invitation table. Each Person can have many Invitations. Each Event can also have many Invitations. If I want a list of Events to which a Person is invited, I can use this HQL query: IQuery query = ...

NHibernate Linq - Duplicate Records

I am having a problem with duplicate blog post coming back when i run the linq statement below. The issue that a blog post can have the same tag more then once and that's causing the problem. I know when you use criteria you can do the followingcriteria.SetResultTransformer(new DistinctRootEntityResultTransformer()); How can I do t...

ASP.NET MVC and User Authentication with NHibernate

I am about to start a new application and am excited about using asp.net mvc and nhibernate. However, the big "problem" is how I handle the user authentication stuff. What are some ways those used to using nhibernate and MVC solve this problem? My thought is let asp.net do its own thing and I do my own thing database wise. Am curios if ...

How to look up an NHibernate entity's table mapping from the type of the entity?

Once I've mapped my domain in NHibernate, how can I reverse lookup those mappings somewhere else in my code? Example: The entity Pony is mapped to a table named "AAZF1203" for some reason. (Stupid legacy database table names!) I want to find out that table name from the NH mappings using only the typeof(Pony) because I have to write a ...

Paging over a lazy-loaded collection with NHibernate

I read this article where Ayende states NHibernate can (compared to EF 4): Collection with lazy=”extra” – Lazy extra means that NHibernate adapts to the operations that you might run on top of your collections. That means that blog.Posts.Count will not force a load of the entire collection, but rather would create a “sel...

Amend field - nvarchar(12) to nvarchar(20)

I've been let down by my Programmer, so I need to change a field size myself today. Basically, a field is limited to 12 characters on a form which I need to change to 20. I've logged on to the SQL database and changed it there, but its still not working on the main site. I've been told I need to change it in FluentNHibernate, but I've ...

How to get the connection string value from hibernate.cfg.xml file?

I'm using Fluent NHibernate and need to get my Connection String from the connection.connection_string property on hibernate.cfg.xml file to create my Session Factory: private static ISessionFactory SessionFactory { get { return = Fluently.Configure() .Database(MySQLConfiguration.Standard.ConnectionString(c => c.FromCo...

Getting error "Association references unmapped class" when using interfaces in model

I'm trying to use the automap functionality in fluent to generate a DDL for the following model and program, but somehow I keep getting the error "Association references unmapped class: IRole" when I call the GenerateSchemaCreationScript method in NHibernate. When I replace the type of the ILists with the implementation of the interfaces...

fluentnhibernate and nhibernate validator version error

We have a project using FluentNibernate to map the entities. Now I need to add some format validation to these maps. For Nullable, Length and such we are currently using the mappings. I added NHibernate Validator to the project, but received a compile time error about needing NHibernate version 2.1.2.4000. So I upgraded to that versio...

Entity with Guid ID is not inserted by NHibernate

I am experimenting with NHibernate (version 2.1.0.4000) with Fluent NHibernate Automapping. My test set of entities persists fine with default integer IDs I am now trying to use Guid IDs with the entities. Unfortunately changing the Id property to a Guid seems to stop NHibernate inserting objects. Here is the entity class: public cla...

nhibernate activerecord lazy collection with custom query

What i'm trying to accomplish, is having a temporal soft delete table. table Project(ID int) table ProjectActual(ProjectID int, IsActual bit, ActualAt datetime) Now is it possible to map a collection of actual projects, where project is actual when there is no record in ProjectActual.ProjectID = ID, or the last record sorted by Actual...

Using Lite Version of Entity in nHibernate Relations?

Is it a good idea to create a lighter version of an Entity in some cases just for performance reason pointing to same table but with fewer columns mapped. E.g If I have a Contact Table which has 50 Columns and in few of the related entities I might be interested in FirstName and LastName property is it a good idea to create a lightweight...

How to refer to enum values inside nhibernate formula mapping specification?

Dear ladies and sirs. I have two entities types: RunContainer parent entity type Run child entity type Run has a property Status, which is of type RunStatus, like so: public enum RunStatus { Created, Starting, // ... } public class Run { public int ContainerId { get; private set; } // ... public RunStatus Status { get...

An item with the same key has already been added.

Can someone advice me how to prevent this error. An item with the same key has already been added.? // Failed to find a matching SessionFactory so make a new one. if (sessionFactory == null) { Check.Require(File.Exists(sessionFactoryConfigPath), "The config file at '" + sessionFacto...

Fluent NHibernate and PostgreSQL, SchemaMetadataUpdater.QuoteTableAndColumns - System.NotSupportedException: Specified method is not supported.

Hello! I'm using fluentnhibernate with PostgreSQL. Fluentnhibernate is last version. PosrgreSQL version is 8.4. My code for create ISessionFactory: public static ISessionFactory CreateSessionFactory() { string connectionString = ConfigurationManager.ConnectionStrings["PostgreConnectionString"].ConnectionString; IPersist...

Problem with NHibernate and saving - NHibernate doesn't detect changes and uses old values.

When I do this: Cat x = Session.Load<Cat>(123); x.Name = "fritz"; Session.Flush(); NHibernate detects the change and UPDATEs the DB. But, when I do this: Cat x = new Cat(); Session.Save(x); x.Name = "fritz"; Session.Flush(); I get NULL for name, because that's what was there when I called Session.Save(). Why doesn't NHibernate det...

nHibernate Mapping Question

I have the following tables with a one to many relationship one list: List ---- Id Name Type etc... ListItem ---- Id ListId Label etc.. I have the following classes: public class List { public Guid Id{get;set;} public IList<ListItem> {get;set;} } public class ListItem { public Guid Id{get;set;} public string...

NHibernate.Linq to Criteria API translation help needed

I'm not sure how to add paging to this: Session.Linq<Article>() .Where(art => art.Tags.Any(t => t.Name == tag)).ToList(). So i decided to use Criteria API. var rowCount = Session.CreateCriteria(typeof(Article)) .SetProjection(Projections.RowCount()).FutureValue<Int32>(); var res = Session.CreateCriteria(typeof(Article)) .Add(/...

Interface -> Entity Mapping

Hi guys, Suppose I have a few definitions like so: public interface ICategory { int ID { get; set; } string Name { get; set; } ICategory Parent { get; set; } } public class Category : ICategory { public virtual int ID { get; set; } public virtual string Name { get; set; } public virtual ICategory Parent { get; ...

NHibernate UserType value on object

Hi. I'm using a UserType to maintain a column (Created) in my db. When saving to db i simply check if the property in question equals DateTime.MinValue, and if so updates it to DateTime.Now (overriding NullSafeSet). This update however, is not immediately reflected by nhibernate, and if i load the object again without evicting it, th...