nhibernate-mapping

In a Domain object how do I get a filtered set of related child entities without accessing repository?

Hi there, I'm using NHibernate, and have a one to may mapping set up. Let's call it Customer -> Orders This all works, and I can get all the orders for the customer. Now, I'd like to filter these orders, let's say I just want orders between run time determined dates. public class Customer { ... // mapped from NHibernate mappi...

Fluent NHibernate table per hierarchy mapping problem

Hello, I'm using Fluent NHibernate version 1.0.0.579 (latest version at this date). I have an abstract Activity class and several inheriting classes, eg. DummyActivity. All of them use the same table Activities, and all of them have a discriminator value based on an integral type which points to a mapping in the project (not a FK in dat...

NHibernate HiLo - new column per entity and HiLo catches

Im currently using the hilo id generator for my classes but have just been using the minimal of settings eg <class name="ClassA"> <id name="Id" column="id" unsaved-value="0"> <generator class="hilo" /> </id> ... But should I really be specifying a new column for NHibernate to use foreach entity and providing it with a ...

Two classes mapped to same table(one readonly) must be in correct order?

Consider these two classes mapped to the same table. One is readonly via mutable="false". <class name="Funder" table="funder"> <id name="id"> <generator class="identity" /> </id> <property name="funder_name" /> <property name="contact_name" /> <property name="addr_line_1" /> <property name="addr_line_2" /> ...

Fluent Nhibernate left join

I want to map a class that result in a left outer join and not in an innner join. My composite user entity is made by one table ("aspnet_users") and an some optional properties in a second table (like FullName in "users"). public class UserMap : ClassMap<User> { public UserMap() { Table("aspnet_Users"); Id(x => x....

NHibernate maps to base instead of subclass.

In my business model I have Entity class (IPoint interface) that has a list of child elements of the same type. The link in DB is made via many-to-many table. The Entity has also discriminator for subclassing (IPoint implementations). At first I made simple many-to-many mapping for this and all was working good. But then I've made (as b...

Unique results from joined queries with NHibernate LINQ provider

I'm using NHibernate 2.1 with the LINQ provider and the results I get back from this query have multiple root nodes: public IList<Country> GetAllCountries() { List<Country> results = (from country in _session.Linq<Country>() from states in country.StateProvinces orderby country.Dis...

How do you map aggregate functions in NHibernate?

I'm new to NHibernate and trying to create my first mapping. I have created a class like this (my example is simplified): public class Buyer { public int BuyerID { get; set; } public string Name { get; set; } public decimal AverageOrderAmount { get; private set; } public DateTime LastOrderDate { get; private set; } } ...

NHibernate Mapping for User Roles and Privileges

The Scenario I've been banging my head against the wall trying to figure out the correct mapping for 3 entities: User, Role, and Privilege. In my application, Users can have Privileges, which just give a user additional permissions. Users can also have Roles which are essentially privileges that require additional properties. For inst...

Fluent NHibernate / NHibernate Mappings

I have a parent table and relationship table to find child parent relationship. I need to find child, parent and its siblings... EMPLOYEE_RELATION has columns EMPLOYEE_ID and PARENT_ID that saves the relationship. Here's what SQL looks like. How do I map this to Fluent NHibernate / NHibernate. select V1.PARENT_ID AS PARENT_ID, ...

Can I have a collection of IUserType instances?

Is it possible to have a collection of entities that are mapped via an IUserType? For example: class Foo { public int Id { get; set; } public ISet<Special> Items { get; set; } } class Special { public Special(string columnValue) { _val = columnValue; } public override string ToString() { re...

Mapping a collection of foreign keys in nhibernate

I have tables like this: tblUsers int UserID string UserName tblUsersInRoles int UserID int RoleID tbleRoles int RoleID string RoleName A user can be in many roles. Is there a way to create my mapping file for my users so that my users object contains a list of Roles? I've figured out to do it so that I have a list of RoleID's lik...

Mapping tree structure with Fluent NHibernate

I am having trouble to map a tree structure using Fluent NHibernate, without also having to put in what I believe is a hack. Consider the following classes: Node (abstract, has int Id and GroupNode Parent (if null, the node resides in the root node)) GroupNode (inherits from Node, has IList<GroupNode> Groups and IList<ItemNode> Items)...

Custom Converters for domain types using NHibernate

Hi, My domain model is using System.Net.Uri to represent URLs, and System.Drawing.Color to represent colors. In the db, uris are simply nvarchars and colours are web (hex) rgb values. Using NHibernate, is there some way to map between these values using some custom mapper? I don't need to query against these items, but it would be nic...

Nhibernate mapping without id

Hi I have a Parameter table in my sql server db. This table contains 20 or so fields, but only ONE record. This table will always contain one record, and also contains no Id or key field. How do you map this with NHibernate? ...

NHibernate: using an existing public int field as record Id

I have an existing class that I'd like to persist as-is. class Foo { public int Id; ... } I have the following ClassMap: class FooMap : ClassMap<Foo> { Id(x => x.Id); ... } Building a session factory results in an invalid cast exception. My setup works if my entity class has the standard "public virtual int Id { get...

NHibernate: One class contained by many classes

I have a class called Point {int x; int y; } . And I have two other classes say A and B both of which contain a List of Point. What is the proper NHibernate mapping for this scenario? Thank in advance ...

Do unidirectional associations lead to non-required foreign key fields through NHibernate

Update Added mappings below Question summary I have a database with many required foreign key fields and a code base with many unidirectional associations. I want to use NHibernate, but as far as I can tell, I either have to make the foreign key fields in the database NULLable (not a realistic option) or change the associations to bidir...

NHibernate proxy question

I have a quick question. If I have an interface from which my class derives, I can use that interface as a proxy for lazy loading. If I have an abstract class from which my class derives, can I use the abstract class as a proxy for lazy loading? Thx alot! ...

Fluent NHibernate HasManyToMany() Save/Update Problem

Hi, i have the following code, which is supposed to give specific functionality but it isn't :S anyway, here's my problem: http://img525.imageshack.us/img525/1315/diagramp.png here's the mapping code: public class UsersMap : ClassMap<User> { public UsersMap() { this.Table("Users"); Id(x => x.UserName).Generat...