nhibernate-mapping

Using part of a composite primary key in a composite foreign key in NHibernate

We have a fairly big DB (~200 tables) which almost entirely uses composite primary keys and composite foreign keys, using a single "base table" from which every other table inherits part of its primary key: Parent has single column primary key ParentId Child has composite primary key (ParentId, ChildId) and foreign key ParentId Nephew ...

self-reflexive n:m relation using composite keys in nhibernate

I have a legacy database with 3 tables like this: The Items table contains all the Items in a Plan. The Structure table defines the relation between the items. A parent item is defined by company, year, planId and parentItem of table structure mapping to company, year, planId and id of table item. A child item is defined by company, yea...

setting type and length on composite-key property in fluent nhibernate

In hbm mappings I can <composite-id> [..] <key-property name="someStringProperty" column="somefield" type="AnsiString" lenght="8"/> </composite-id> How do I do that (setting type and length) in Fluent? Edit: I posted this on support.fluentnhibernate.org. I included some modi...

NHibernate, one column two meanings, positiv/negative

Hi We have a large management application and we do alot of logging for every action, who did what and at what time. However we have more and more automatic systems which we would like to differentiate aswell. In all our tables we have a column called PerformedBy which is an int. This has always been a reference to a Table called Emplo...

NHibernate 3.0 beta1 Bidirectional One-To-Many Cannot Add Child Object

Hi guys, In short, the problem is that, when add child object to the collection property of the parent object without explicit setting the parent property of the child object, the insert will fail. Let's take a example: NOTE: I'm using NHibernate 3.0 beta1. Example: Product-Category Senario: (1) Database Schema: Category (Id, Name)...

NHibernate mapping problem - Could not initialize proxy - no Session.

I have just started to learn NHibernate, and are following tutorials. On my own learning project, I have made up a problem for myself. I have two tables: Team: TeamId* Name Match: MatchId* TeamAId TeamBId The model entities are: Team public virtual int? TeamId { get; private set; } public virtual string Name { get; set; } public v...

Fluent NHibernate Joined References Ignoring Cascade Rule

I'm using Fluent NHibernate in an attempt to improve testability and maintainability on a web application that is using a legacy database and I'm having some trouble mapping this structure properly: I have two tables that really represent one entity in the domain, and so I'm using a join to map them as such, and a third table that repre...

NHibernate table-per-subclass - adding a new sub class to an existing base class

I have three classes mapped using the table-per-subclass class mapping strategy. The tables are: Images - ImageId, FileName, ImageData CategoryImages - CategoryId, ImageId ProductImages - ProductId, ImageId We are mapping like so: <class name="CatalogImage" table="Images"> <id name="Id" column="ImageId"> <generator class="guid.com...

nhibernate polymorphism mapping

I have two entities that I need to treat polymorhically, each of which has a similar "business id" type of property. As you might expect, there is semantic meaning to each id in the domain, and there is an object type to represent it. In one entity, a Project, the domain language of this property is a ProjectCode. In the other entity, an...

NHibernate not deleting child object

I can't get NHibernate to delete this child object, it completes without throwing any exceptions and without deleting anything: public void DeleteW9(int vendorId, int vendorW9Id) { var vendor = vendorRepository.Get(vendorId); var W9 = vendor.W9.Where(x => x.Id == vendorW9Id).First(); vendor.W9.Remove(W9);...

Nhibernate mapping issue: a property whose type is a superclass

I have an NHibernate object that is a superclass (let's call it "Super"), and a subclass that inherits from it (let's say it's called "Sub"). <class name="Super" table="SuperThings"> <id name="Id" type="System.Int32" column="SuperId"> <generator class="identity" /> </id> <joined-subclass name="Sub" table="SubThings...

Getting an index was out of range exception with NHibernate

Hi all, I'm currently building a web application with MVC and NHibernate. Now when i want to get information out of the database I get an index was out of range exception. The current situation is as follows. I got the mapping files of three database tables: A table to store a group with a one-to-many relationship with subscriberingro...

Preventing duplicate tag names with many-to-many NHibernate mapping

I'm using NHibernate to persist my Item class to a SQL database. The Item class has a property Item.Tags of type ICollection<Tag> which I am mapping using the following NHibernate configation. <set name="Tags" table="TagLinks" cascade="all" lazy ="false"> <key column="ItemId" /> <many-to-many class="Tag" column="TagID" /> </set> A...

How to map property to first of many in Fluent NHibernate?

Given a parent child relationship between User and FailedLogin where a user has many failed logins. I'd like to map this into class User { public virtual FailedLogin LastFailedLogin { get; set; } } class FailedLogin { public virtual User User { get; set; } public virtual DateTime AttemptOn { get; set; } } So that the Las...

Nhibernate mapping - Can a child hold a reference to its parent collection?

I am new to NHibernate and I'm trying it out by porting a small webforms app to use it. I am trying to figure out if its possible to map (hmb.xml maps) the following assignments: public class Foo { public List<Bar> Children { get; set; } public void AddBar(Bar b) { Children.Add(b); b.OwnerCollection = Childr...

SQL Server table-relations necessary with NHibernate?

Dear All! This may be a really silly question, but I've found no answer on google/bing... If I already use NHibernate for persistence with SQL Server, why should I then create all the table-relations on the database-schema? I'm just wondering because it seems to create all the relations, altough I already have defined them in the NHibe...

NHibernate Property Mapping, best practise for type attribute?

I have a little doubt for mapping of property in hbm file. Sometimes I've mapped the string field of my db in this way: <property name="MyPropName" column="MyColumnName" length="20" /> but the same mapping can be wrote in this way: <property name="MyPropName" column="MyColumnName" type="String(20)" /> my question is...what's the b...

How to mapping that tables using NHibernate (Fluent or XML)

Hello guys... Can you help-me with that database : I´m using Fluent NHibernate, but XML helps too... My problem is with ProductPrice table... Thanks Paul ...

Problems filtering entities from an nhibernate mapping with an IInterceptor

I have a set of entities that implement an interface: public interface ILocalised { Culture Culture { get; } } For lots of complicated reasons I need to filter entities which do not have the correct culture after they are returned back from the DB (i.e. I can't use a Filter). My immediate thought was to create an interceptor that ...

NHibernate many-to-many - how to retrieve property from join table and associate it with a child?

I have an existing many-to-many relationship in SQL that is being mapped to my business entities via NHibernate. I want to add a property to the child (Category below) that is only applicable to the relationship between the parent and the child. In SQL, I would add a field to the join table. How do I use NHibernate to pull that value ...