fluent-nhibernate

NHibernate Set Property Default Value

Hi, Is it possible to set the default value of a property in NHibernate? Here is the scenario: I have a self join table Category. The class and table structure are as follows: Category int Id string Name Category ParentCategory Category int Id not null varchar Name not null int ParentCategoryId not null If a category has no parent,...

How does NHibernate know which class properties to put value into?

UPDATED: This is totally wrong assumption. I retested it and sure enough I was mistaken. NHibernate generates SQL that will get all children rows to both Children Lists. Thank sirrocco for the comment. I think the better question is how we could do something like this work. I modified the code a bit from Fluent NHibernate Examples in Wi...

How do you ignore/persist values in MVC when your view-model doesn't have as many fields as your domain model?

I have a site where I'm using fluentNhibernate and Asp.net MVC. I have an Edit view that allows user to edit 8 of the 10 properties for that record (object). When you submit the form and the Model binds, the two un-editable fields come back in the view-model as Empty strings or as default DateTime values depending on the type of proper...

NHibernate: Deleting a collection and re-inserting

Hello, I have a User with related Permissions. Here is what I want: I create a User and add a permission to the User.Permissions collection. It gets saved and everything happens as expected. Then I edit the user and remove the permission. A new user object is then created and the permissions collection is empty. The identifier and...

nhibernate and sessions, please clarify

Hi, I am building a web application, and whenever I make a database call I need a session. I understand creating a session object is very expensive. I am following the repository pattern here: http://blogs.hibernatingrhinos.com/nhibernate/archive/0001/01/01/the-repository-pattern.aspx He uses something called a UnitOfWork to get the ...

does fluent handle the configuration also or I still need configuration.cfg.xml

Hi, I am using fluent for mappings in my web application that uses nhibernate (just setting it up!). Do I use fluent for the database configuration file or I use fluent for that? ...

nhibernate not taking mappings from assembly

Hi I'm using fnh and castle nhib facility. I followed the advice from mike hadlow here: http://mikehadlow.blogspot.com/2009/01/integrating-fluent-nhibernate-and.html here is my FluentNHibernateConfigurationBuilder: public Configuration GetConfiguration(IConfiguration facilityConfiguration) { var defaultConfigurationBuild...

NHibernate not loading one to many children

Yo i have the following nhibernate class: public class User { public virtual int Id { get; set; } public virtual string FullName { get; set; } public virtual IList<RatingItem> RatingItems { get; set; } public User() { RatingItems = new List<RatingItem>(); } public virtual void AddRatingItems(R...

Fluent NHibernate MappingException : could not instantiate id generator

I'm pottering around with Fluent NHibernate to try and get a simple app up and running. I'm running through this Fluent NHibernate Tutorial. Everything seems to be going fine and I've created the required classes etc. and it all builds, but when I run the test, I get an exception. Someone in the comments section of the tutorial has t...

Nhibernate many to one mapping with separate table ?

I've recently started using NHibernate and have very little experience. I have table Projects which can't be changed since it's a part of older system. I need to add ProjectGroup table represeting group of project, so that one project is assigned to only one particular group and group can have many projects assigned to it. I wonder if ...

Fluent Nhibernate, stuggling with one-to-many relationships

Okay so I have two tables: Companies | id int | name varchar(50) and Contacts | id int | name varchar(50) | companyID int In my code I have the following classes public class Company { public int Identity { get; set; } public string Name { get; set; } public IList<Contact> Contacts { get; set; } } ...

Why is nhibernate looking in /bin/debug for the hibernate.cfg.xml?

Hi, I have a class library with all my nhibernate code (domain/mappings using fluent). Now I am just doing some simple tests in a console application, and I am getting an error saying it can't find the configruation file in /bin/debug I have the file in /consoleTests/hibernate.cfg.xml Why would it be looking in the /bin/debug folder...

nhibernate says 'mapping exception was unhandled' no persister for: MyNH.Domain.User

Hi, I am using nHibernate and fluent. I created a User.cs: public class User { public virtual int Id { get; set; } public virtual string Username { get; set; } public virtual string Password { get; set; } public virtual string Email { get; set; } public virtual DateTime DateCreated { get; se...

Fluent NHibernate DuplicateMappingException with AutoMapping

Summary: I want to save two classes of the same name and different namespaces with the Fluent NHibernate Automapper Context I'm writing having to import a lot of different objects to database for testing. I'll eventually write mappers to a proper model. I've been using code gen and Fluent NHibernate to take these DTOs and dump them s...

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); } ...

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...

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...

Fluent nHibernate: How to map 2 tables with no primary keys defined

I have a legacy system where the relationship between 2 tables haven't been defined explictly and there aren't any keys (primary or unqiue defined). The only related columns is 'Username' Something like: Table: Customer Column: Id, Column: Username, Column: FirstName, Table: Customer_NEW Column: Username Column: FirstNameNew I have ...