nhibernate-mapping

IndexOutOfRangeException Deep in the bowels of NHibernate

I have the following mappings: public class SecurityMap : ClassMap<Security> { public SecurityMap() { Table("Security"); CompositeId().KeyProperty(k => k.Id, "SecurityId").KeyProperty(k => k.EndDate); Map(x => x.LastUpdateUser); References(x => x.Company).Columns("Compa...

NHibernate Composition Composite Key problem

I have a class that is composed of 2 composite key objects and they share a column ‘SharedColumn’. This maps fine and the composite classes’s one-to-Many mappings work fine. <class name="PAIR"> <composite-id> <key-many-to-one name="first" class="Class1"> <column name="SharedColumn"/> <column name="Column1" /> ...

NHibernate - How to store UInt32 in database

What is the best way to map UInt32 type to sql-server int type with NHibernate. The value is a picture width/height so negative value are not make sense here. But maybe I should use int because NHibenate doesn't support unassigned ints. ...

NHibernate reuse join table in many-to-many association

I have two domain objects: Product and ProductDictionary, which are both abstract classes and they both have many concrete subclasses. They are connected via many-to-many association. I would like to reuse one join table for all associations between Product and ProductDictionary subclasses, because I don't want to polute my DB with unnec...

Fluent Nibernate putting a where clause in the mapping

Hi, I've got two objects a parent and a child list. In my fluent nhibernate mapping for the parent I want to load the list of the children. However I want this to be conditional, a column in the child table is called "IsDeleted" and I only want to return the children where "IsDeleted" is false. Is it possible to set up a mapping to d...

how to map SampleCount property using NHibernate.

Dear ladies and sirs. I have two tables - Run and Sample, where Sample.RunId is a foreign key linking samples to their runs. I would like to have a SampleCount property in Run, which is the number of Sample objects associated with the particular Run. Is it possible to map such a property in NHibernate mapping of the Run type? Thanks....

How to add a read-only collection property in (Fluent) NHibernate?

I want to control my domain's interaction with a collection, so I thought I'd make the collection protected and provide a read-only wrapper around it so that the contents are visible, but I can ensure that items are not added directly to the collection. So I have the following code: public class MyClass { public virtual ICollectio...

How do I map a one-to-many relationship through a join table?

Hi all, How would I go about mapping the following in NHibernate? My entities and ERD are below. I know how to map a many-many relationship, but dont know how to map the joining table ReportTargets to the Datapoint table. You will notice that there is no ReportTargets entity model as it is not strictly a domain entity. What is the best ...

NHibernate Collection Mapping Help

I have a root object, Policy, that has a compositeKey of PolicyNumber/PolicyDate. The Policy has a one-to-many collection of PolicyDetails which have a composite key of PolicyNumber/PolicyDate/Sequence. Sequence is an assigned value that is set by the application. My Mapping for Policy is below. I'm able to do a get and populate my c...

property Access strategies in nhibernate

What are the access strategies that I can use in the attribute access of the nhibernate xml? Can someone point me the possible values to be used in it? A nice tutorial would be very appreciated. Thanks ...

NHibernate: Populate property Order.TotalAmount from OrderItem.Amount

Hi. I have a class called Order that contains a property called TotalAmount and a list called OrderItems. Each order item is like a product and contains a property called Amount (which is like the price). I would like to have TotalAmount return the sum of amounts of those OrderItems that belong to that property. I know two ways of doin...

NHibernate custom collection type

Hi, I'm having an entity object called Patient and this entity is having a property called Visits which is of type VisitsCollection. VisitsCollections is a child class of IList<Visit> but it also adds some custom logic to the collection (like auto ordering, some validation, notifications, etc..). I need to use the custom collection ty...

NHibernate mapping of one class containing 2 references to the same entity

I have a person class, then have a family class where I have a property Father and a property Mother of type Person. I have a database table for Person and a Family table containing FamilyId, FatherId, MotherId where FatherId and MotherId is foreign keys for PersonId in Person table. How would you go about to map this in NHibernate? ...

NHibernate many to many mapping error - NHibernate.MappingException: Could not determine type for:

Hi, I am having a problem when trying create a many to many mapping. Consider the following tables: CREATE TABLE [dbo].[student] ( [Id] INT IDENTITY (1, 1) NOT NULL, [Name] NVARCHAR(255) NOT NULL, -- Some other stuff... ) CREATE TABLE [dbo].[Subject] ( [Id] INT ...

NHibernate entity loose coupling

Let's say I have an entity called MyItem. It can be included in many "parents", like SomeCollection and SomeOtherCollection. Because it can be included in many parents, and since I don't want MyItem to know about the parents, I'd like to not have any properties in MyItem referencing a parent. And since a parent, like SomeCollection, can...

How to map this class in NHibernate (not FluentNHibernate)?

Suppose I have a database like this: This is set up to give role-wise menu permissions. Please note that, User-table has no direct relationship with Permission-table. Then how should I map this class against the database-tables? class User { public int ID { get; set; } public string Name { get; set; } pu...

HasOne vs References Mapping Fluent NHibernate

Hi, This is the first time I am working with FluentNhibernate Mapping and facing a question of how to reference another table. Any help is appreciated: I have several tables named CD_varname and all these contain two columns - CODE and DESCR. I have one main table called Recipient and it has, say two columns, called ALIVE and SEX, bot...

FluentNHibernate acts differently on different machines

I have run into an issues with FluentNHibernate that i hope someone can help me with. I have a many-to-many relationship between two classes named CampaignAreas and CampaignProducts. Sadly Fluent doesn't map the relation-table to the same table name on my machine as it does on my colleagues. It is named CampaignProductsToCampaignAreas a...

Fluent NHibernate and computed properties

I'm using Fluent NHibernate, and auto-mapping the classes. I have a computed property in a class along the lines of public virtual DateTime? LastActionTimeStamp { get { return Actions.Count == 0 null : Actions.OrderByDescending( a => a.TimeStamp).ElementAt(0).TimeStamp; } } This wasn't mapped with the rest...

nhibernate will not cascade delete childs

The scenario is as follows, I have 3 objects (i simplified the names) named Parent, parent's child & child's child parent's child is a set in parent, and child's child is a set in child. mapping is as follows (relevant parts) parent <set name="parentset" table="pc-table" lazy="false" fetch="subselect" cascade="a...