nhibernate-mapping

Generate XML mappings from fluent Nhibernate

How do I generate xml mappings files as part of my tests in MappingIntegrationTests I need to manually check if the fluent mappings correlate to the mappings in the leagcy project. ...

NHibernate: Map one class to two identical tables

I need to map one entity to two tables (Invoice and InvoiceHistory). It's not up to me to merge the two database tables in one and add a status column to differentiate them. The two tables have the exact same structure, but, as the name says, InvoiceHistory keeps a history of old invoices whereas Invoice stores active invoices. (the ex...

NHibernate.TypeMismatchException: Provided id of the wrong type. Expected: System.Int32, got System.Int64

Am using the following query to get a Client. The Client has a public Id of type long. var client = Session.CreateQuery("from Client as c where c.Id = :Id").SetParameter("Id", 1, NHibernateUtil.Int64).UniqueResult<Client>(); Am getting the error: NHibernate.TypeMismatchException: Provided id of the wrong type. Expected: System.I...

Add multi-column unique constraint on foreign Key using fluent-nhibernate automapping

Hi everybody, I'm an NHibernate and fluent-nhibernate newbie. And I've got some problem with unique constraint and nhibernate mapping. I've got the following part of domain model. public class Batch { public virtual int Id {get; set;} public virtual string Name {get; set;} public virtual IList<BatchParameter> BatchParamete...

[Nhibernate] CreateQuery and CreateCriteria generating different SQL queries

Client has a Report, Configuration etc properties. A client can have only one of each. Also, each report can belong to only one Client. This is in a way a one-to-one relationship. Therefore my Report table has a foreignkey column clientID. Same for the Configuration and other tables. Now as per the definition of one-to-one that i read ...

Mapping a a simple collection of elements with Fluent NHibernate

I'm trying to map a collection of enum values with Fluent NHibernate. IList<EnumType> lst; I can't find any documentation about it but I'm quite sure it should be possible. I had no problem at all with mapping a collection of Entities. Thanks, Leonardo ...

Relating classes in NHibernate

I have a situation where I have a class that is referenced by several other classes. For example, my ContactInformation class is referenced by multiple different classes, such as Customer, Business, Location, etc. Since it is referenced by multiple classes, I am unsure of how to make a two-way mapping so I can insert a Customer with it...

How to map a collection of abstract classes in nhibernate

I have been reading Nhibernate in Action, but the section on mapping polymorphic collections is a little too short on how to do this. I have the following code [Class] [Discriminator(Column="MachineType",TypeType=typeof(string))] public abstract class Machine { [Property] public string Name{get;set;} } [Subclass(DiscriminatorValue...

Hibernate many-to-many with map collection

I have two tables "Station" and "Route". Route can contain many stations and every station can be a part of the different routes. The logical solution is to create a table with 'station_id' and 'route_id' fields and there are lot of examples on the internet how to organize all of this stuff with hibernate. But I need to store the order n...

nhibernate datasource sqlite relative filepath

Hi all, I have the following nhibernate cfg file: <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property> <property name="connection.driver_class">NHibernate.Driver.SQLite20Driver</property> <property name="connection.connection_string">Data Source=dbFile.db;Version=3</property> <property name="di...

Fluent nHibernate

I am having a bit of trouble figuring out how to make a specific design in fluent nHibernate. I have a small workflow prototype with two aspects to it. First, you can design a workflow, that has a collection of 'phases' and a phase has a collection of 'Tasks'. I have this part loading and saving using nHibernate. Second part, these wor...

NHibernate - map a collection from a custom SQL Query?

Hi, I'd like NHibernate to fill a collection on my class from a custom query. My setup is somewhat like this: Class A has a one-to-many relation to Class B. B has two many-to-one relationships to Class C, From and To. In Class B, I want to be able to map a collection of C instances, based on the From and To relations. The collection s...

Why Fluent NHibernate vs. hbm XML files?

While this is a subjective question, as a new NHibernate user, I'm curious as to why one would choose Fluent vs traditional XML mapping. From my standpoint, when I first worked with NHibernate, I used the Fluent interface, but ran into some roadblocks and had a hard time finding adequate documentation for the Fluent interface for anythi...

Fluent-NHibernate : how to map one-to-many relationship into 3 tables (many-to-many, kinda)

I have to 2 entities like this: class A { int id { get; set; } string Name { get; set; } } class B { int id { get; set; } A RefToA { get; set; } string Name { get; set; } } How can I map this 2 classes so that i would have 3 tables like this: table A with 2 columns: id and name table B with 2 columns: id and name t...

nhibernate mapping: A collection with cascade="all-delete-orphan" was no longer referenced

Hi All I am having some probs with my fluent mappings. I have an entity with a child collection of entities i.e Event and EventItems for example. If I set my cascade mapping of the collection to AllDeleteOrphan I get the following error when saving a new entity to the DB: NHibernate.HibernateException : A collection with cascade="all-...

How to specify a mixed table-per-subclass -> table-per-hierarchy in NHibernate HBM?

I'm mixing table mapping strategies to store a class hierarchy via NHibernate 2.1.2. I'm not using Fluent NHibernate. I understand how to map a table-per-hierarchy -> table-per-subclass structure, but not the other way around, as the XML is invalid after adding the discriminator. Here's the HBM extract: <class name="Base1" table="Ba...

Alternatives for NHibernate mappings?

Are there any good alternative to NHibernate's xml mappings? I have seen Fluent. All I look for is high maintainability. UPDATE : I would like to know the performance issues related with using fluent because I guess it is going to create xml mappings from the class (which can be time consuming - my guess) Thanks ...

NHibernate + Cannot insert the value NULL into...

I've got a MS-SQL database with a table created with this code CREATE TABLE [dbo].[portfoliomanager]( [idPortfolioManager] [int] NOT NULL PRIMARY KEY IDENTITY, [name] [varchar](45) NULL ) so that idPortfolioManager is my primary key and also auto-incrementing. Now on my Windows WPF application I'm using NHibernate to help with adding...

nhibernate custom collection handling

Hello I have a working one to many relationship (NOT bbidirectional) where Resource has a set of many Allocations implented as shown below. The domain needs to do more with the collection of allocations that just manage it with AddAllocation, RemoveAllocation, etc. So from an object perspective, I'd like to put that extra logic that is ...

C# Mapping struct in ActiveRecord

Hi here. i am making a little application to help me balance my checkbook. i am using Castle ActiveRecord to map the object properties to the database. now here is the problem. as i am making a money program i made a struct Currency The struct: public struct Currency { private long amount; private CurrencyType currencyType; ...