nhibernate-mapping

Will the following NHibernate interface mapping work?

I'd like to program against interfaces when working with NHibernate due to type dependency issues within the solution I am working with. SO questions such as this indicate it is possible. I have an ILocation interface and a concrete Location type. Will the following work? HBM mapping: <class name="ILocation" abstract="true" table="IL...

Types from multiple assemblies and namespaces in nhibernate mapping files

You can specify the namespace and assembly to use types from at the top of HBM files: <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="MyCorp.MyAssembly" namespace="MyCorp.MyAssembly.MyNamespace"> Can you use types from multiple assemblies / namespaces within the same mapping file, and if so what is the syntax for doing...

Polymorphic NHibernate mappings

I have an interface IUserLocation and a concrete type UserLocation. When I use ICriteria, specifying the interface IUserLocation, I want NHibernate to instantiate a collection of the concrete UserLocation type. I have created an HBM mapping file using the table per concrete type strategy (shown below). However, when I query NHibernate ...

Fluent NHibernate: mapping complex many-to-many (with additional columns) and setting fetch

I need a Fluent NHibernate mapping that will fulfill the following (if nothing else, I'll also take the appropriate NHibernate XML mapping and reverse engineer it). DETAILS I have a many-to-many relationship between two entities: Parent and Child. That is accomplished by an additional table to store the identities of the Parent and C...

NHibernate - auto generate timestamp on create and update ?

I am trying to map an entity in NHibernate, that should have an Updated column. This should be the DateTime when the entity was last written to the database (either created or updated). I'd like NHibernate to control the update of the column, so I don't need to remember to set a property to the current time before updating. Is there a b...

NHibernate MySQL Mapping Set Column Type

In my MySQL database, I have the following column type. Field | Type | Null | ---------------------------------- Column_priv | set('Select','Insert','Update','References') | No | And I cannot figure out what to map this to. Can anyone tell me how I can map this to something? ...

Mapping multiple foreign keys to one table

Hi I'm using Fluent Nhibernate, i need to create mappings for 2 tables: Simplified, they look like this: TAXI ( Id int primary key Name varchar ) ORDER ( Id int primary key RedirectedFrom int foreign key on TAXI.Id RedirectedTo int foreign key on TAXI.Id ) So, two foreign keys from table TAXI refer to table ORDER Q: Is tha...

NHibernate Unique Constraint on Name and Parent Object fails because NH inserts Null

Hi, I have an object as follows Public Class Bin Public Property Id As Integer Public Property Name As String Public Property Store As Store End Class Public Class Store Public Property Id As Integer Public Property Bins As IEnumerable(Of Bin) End Class I have a unique constraint in the database on Bin.Name and ...

Restricting deletion with NHibernate

I'm using NHibernate (fluent) to access an old third-party database with a bunch of tables, that are not related in any explicit way. That is a child tables does have parentID columns which contains the primary key of the parent table, but there are no foreign key relations ensuring these relations. Ideally I would like to add some forei...

Fluent NHibernate - Cascade delete a child object when no explicit parent->child relationship exists in the model

I've got an application that keeps track of (for the sake of an example) what drinks are available at a given restaurant. My domain model looks like: class Restaurant { public IEnumerable<RestaurantDrink> GetRestaurantDrinks() { ... } //other various properties } class RestaurantDrink { public Restaurant Restaurant { get; ...

Map derived class as an independent one with FNH's Automap

Hi! Basically, I have an ImageMetadata class and an Image class, which derives from ImageMetadata. Image adds one property: byte[] Content, which actually contains binary data. What I want to do is to map these two classes onto one table, but I absolutely do not need NHibernates' inheritance support to kick in. I want to tailor FNH Aut...

How do I map a one-to-one value type association in an joined-subclass?

I've got a class hierarchy mapped using table-per-subclass, and it's been working out great: class BasicReport { ... } class SpecificReport : BasicReport { ... } With mappings: <class name="BasicReport" table="reports"> <id name="Id" column="id">...</id> <!-- some common properties --> </class> <joined-subclass name="Sp...

FluentNHibernate - ClassMap vs IAutoMappingOverride

In FluentNHibernate when should I use ClassMap and when IAutoMappingOverride<Entity> for my EntityMap classes. public class PostMap : ClassMap<Post> { public PostMap() { ... } } vs public class PostMap : IAutoMappingOverride<Post> { public void Override(AutoMapping<Post> mapping) { ... } } ...

Fluent many-to-many: Deleting one end does not remove the entry in the relation table

I have two classes (Parent, Child) that have a many-to-many relationship that only one end (Parent) knows about. My problem is that when I delete a "relation unaware" object (Child), the record in the many-to-many table is left. I want the relationship to be removed regardless of which end of it is deleted. How can I do that with Fluent...

How to fine tune FluentNHibernate's auto mapper?

Okay, so yesterday I managed to get the latest trunk builds of NHibernate and FluentNHibernate to work with my latest little project. (I'm working on a bug tracking application.) I created a nice data access layer using the Repository pattern. I decided that my entities are nothing special, and also that with the current maturity of ORM...

Nhibernate: building a List<string> through <component>

If I have a field in the db which stores a set of comma separated strings (says tags), how can I instruct fluent Nhibernate to pick it up at List<string>() e.g. Public IList<string> Tags {get; set;} Db field values: Mvc, .net, FNH ...

Mixing inheritance mapping strategies in NHibernate

I have a rather large inheritance hierarchy in which some of the subclasses add very little and others add quite a bit. I don't want to map the entire hierarchy using either "table per class hierarchy" or "table per subclass" due to the size and complexity of the hierarchy. Ideally I'd like to mix mapping strategies such that portions ...

many-to-many mapping in NHibernate

I'm looking to create a many to many relationship using NHibernate. I'm not sure how to map these in the XML files. I have not created the classes yet, but they will just be basic POCOs. Tables Person personId name Competency competencyId title Person_x_Competency personId competencyId Would I essentially create a List in each POC...

NHibernate: Dynamically swapping a single domain model between multiple physical data models

Hi In this article Ayende describes how to map a single domain model to multiple physical data models. Is it possible to extend this principle such that the mapping can chosen dynamically? So for example, imagine we had an entity that could be written to the same physical schema in three ways depending on its current status, and lets a...

Mapping of interconnection with nhibernate

I have to describe interconnection between objects. public class Entity { public string Name {get;set;} public IList<Entity> Connections {get;set;} } How can i persist this? I add another layer of complexity: querying on a specific date a connection between two entities can't be already defined. So probably I need a support t...