nhibernate-mapping

NHibernate deleting association links

I have 2 classes in a many-to-many relationship, each with an ICollection of the other: public class Person { public ICollection<Building> Buildings { get; private set; } } public class Building { public ICollection<Person> People { get; private set; } } In the mapping file, they're declared as many-to-many: <class name="Person" ...

<map> with <index-many-to-many> won't save in NHibernate

I have the following mapping: <?xml version='1.0' encoding='utf-8'?> <hibernate-mapping assembly='Core' namespace='Core.Models' xmlns='urn:nhibernate-mapping-2.2'> <class name='Basket'> <id name='Id' column='id'> <generator class='native'/> </id> <property name="ExternalId" /> <map name="I...

How to map blog archive using NHibernate

I would like to format a blog archive like below given Year=2008 and Month=2 (February): 2009 2008 March February Article C Article B Article A January 2007 I have the following classes: public class BlogArchive { public int Year { get; set; } public int Month { get; set; } public List<BlogYear> Years { get; set; } }...

NHibernate Save, Delete, Save yields unique key violation

Hi, I have a scenario where I need to do the following in a transaction: 1. Save a model with a unique key 2. Delete that model 3. Save a new model with the same unique key the first one had. I'd expect this to work just fine, but I get a unique key violation. NH Profiler also shows that the delete statement is not issued before the s...

How to manage a multiple-level class hierarchy in nhibernate with table per class hierarchy strategy?

I am trying to implement my object hierarchy in one table with the "table per class hierarchy" strategy in NHibernate. I'm getting an error with my NHibernate mapping that can be easily reproduced with a simple example. The error is: System.NotSupportedException: Attempting to parse a null value into an sql string (column:activity0_.T...

Collection lookups; alternative to Dictionary

Hello: A TimeSheetActivity class has a collection of Allocations. An Allocation is a value object that is used by other objects in the domain as well, looking something like this: public class Allocation : ValueObject { public virtual StaffMember StaffMember { get; private set; } public virtual TimeSheetActivity Activity { get;...

1 table = 1 class + 1 one of 2 abstract class

Hi I have two tables which looks something like this Table Queue int ID; string Name; int MessageID; string To string From string Topic string Email Table Message int ID int MessageType This is a rather simplified version, but what we did in the classes was to create 1 class named class Queue int ID string Name Message...

MySQL & NHibernate. How fix the error: Column 'ReservedWord' does not belong to table ReservedWords?

"I am getting a weird error when using NHibernate. And I don't know what is causing this error. I am new to the whole Visual Studio and NHibernate, but not to Hibernate. I used Hibernate in the past in Java projects. Any help would be appreciated in pointing me where my error is. I am using Visual Studio 2008 SP1 with Mysql 5.1. Below...

How to map a many-to-many linking table to use another schema?

I have a few classes that I map to non-default schema using NHibernate.Mapping.Attributes like this: [Class(Lazy = true, Schema = "NonDefaultSchemaName")] public class Class1 I also have some many-to-many mappings: [Set(Inverse = false, Table = "Class1ToClass2", Lazy = true, Cascade = "none")] [Key(1, Column = "Class1ID")] [ManyToMan...

How can I make NHibernate aware of a first-class "Null Object", without database persistence?

I would like to make use of the Null Object pattern in my domain, but I don't want to have records in my database that relate to it - I would prefer it if NHibernate were able to map a SQL null value to my Null object, and vice versa. Is this possible (using Fluent NHibernate for mappings) P.S. This seems like it is a fairly common iss...

How to map this model

Hello: A TimeSheetActivity class has a collection of Allocations. An Allocation is a value object (immutable) looking something like this: public class Allocation : ValueObject { public virtual StaffMember StaffMember { get; private set; } public virtual TimeSheetActivity Activity { get; private set; } public virtual DateTi...

NHibernate inheritance question

Hi, Currently I have the following classes: class Article with properties id, title and body class Question : Article with an extra PostedBy property Then I have a table called Article with the above properties and a table called questions with an ID a foreign key articleID and a PostedBy. Both are in different schemas I would like t...

Using Fluent NHibernate Auto Mapping to map IDs of type object from base Entity class

In the project I'm working on now, we have base Entity class that looks like this: public abstract class Entity<T> where T : Entity<T> { public virtual object Id { get; protected set } // Equals, GetHashCode overrides, etc... } Most classes inheriting from Entity should map Id to int column in SQL Server database, but at l...

How do I get fluent nhibernate to create a varbinary(max) field in sql server

Hi, How can I get fluent nhibernate to create a varbinary field in a sql server 2005 table that uses a field size of varbinary(max)? At the moment I always get a default of varbinary(8000), which isn't big enough as i'm going to be storing image files. I've tried using CAstle.ActiveRecord but havent had any success yet. [ActiveRecord...

NHibernate, saving IDictionary : TransientObjectException

In my class Case I have an IDictionary with Entity (a class) as key and Roles (an enum) as value. When trying to save a new instance (non-persisted) of Case, where the IDictionary is filled with new instances of Entity I get the following error: NHibernate.TransientObjectException: object references an unsaved transient instance - sa...

NHibernate Mapping: Simple Join on a Foreign Key

The Tables Currencies ---------- CurrencyId INT IDENTITY PK IsoCode4217 CHAR(3) -- "USD", "GBP", "EUR", etc Users ---------- UserId INT IDENTITY PK CurrencyId FK REFERENCES Currencies (CurrencyId) The Mapping The current application has a Currency object that needs the IsoCode4217 value. A Currency is not an entity in this applicat...

help needed on Nhibernate mapping (Parent/Child relationship)

I am new to Nhibernate and I am using Nhibernate 2.1.0 RC1. In C# I have the following classes: public class Application { public virtual int Id { get; set; } public virtual Applicant Applicant { get; set; } } public class Applicant { public virtual int Id { get; set; } public virtual string FirstName { get; set; } ...

Fluent NHibernate - How to use/map a database view to populate a contained collection?

I have these classes: public class FloorFill { protected FloorFill(){} public virtual ProductCatalog Catalog { get; set; } public virtual Inventory BatchedItem { get; set; } public virtual Transaction Batch { get; set; } public virtual int ItemReference { get; set; } public virtual IList<InventoryLocation> Backst...

How can you map a collection of strings in NHibernate using a many-to-many relationship?

Given the following fixed domain model: public class Sentence { public int Id { get; private set; } public string Author { get; set; } public string[] Words { get; set; } } And the following proposed normalized database schema: create table Sentence ( Id int identity(1,1) not null primary key, Author varchar(450) ...

NHibernate with models having properties that are classes

I'm using FluentNHibernate but NHibernate XML will do. Say I have this model public User { public User() { ProfilePicture = new Picture(); } public Guid Id { get; private set; } public Picture ProfilePicture { get; set; } } public Picture { int width; int height; } How do I tell NHibernate how to ...