nhibernate-mapping

Fluent NHibernate Mapping a column against one of two columns

I'm dealing with some legacy vendor code that I can't modify. I'd like to wrap the database with an abstraction layer that is easier to use. Given the following two tables, I need to create a mapping for Process.Route that will find the matching Route for a given Process, but that can be either dbo.Route.SourceProcessID or dbo.Route.De...

NHibernate: mapping single column from many-to-one to a primitive type

I have a following mapping: <set name="People" lazy="true" table="ProjectPeople"> <key column="ProjectId" /> <composite-element class="PersonRole"> <many-to-one name="Person" column="PersonId" cascade="save-update" not-null="true" /> <many-to-one name="Role" column="RoleId" cascade="save-update" not-null="true" /> </compo...

NHibernate: SaveOrUpdate by <natural-id>

Is there an easy way to make NH INSERT or UPDATE an entity depending on whether there is already an entity with same <natural-id />? The entity is mapped to another (root) one using <many-to-one cascade="save-update" />. ...

Using NHibernate Identifier Identity Generator

i have read in more then one place that using NHibernate's Identifier as Primary Key is considered a bad practice because the id are generated at the server side and hence we need a reply from the server about the generated ids. (i think that i have also seen a post by Ayende that says that ms-sql server may have problems generating iden...

NHibernate executing extraneous select statements

Problem When executing a get for an entity with a many-to-one relationship with outer join set to true, not-found set to ignore and the entity row on the one side does not exist, an extra select is executed by NHibernate trying to load it even though the previous select which was just executed could not find it. Question Why is this e...

Discriminated unions in NHibernate

I'm wondering if there's any relatively easy way to extend NHibernate to support F#'s discriminated union. Not just a single IUserType or ICompositeUserType, but something generic that I can re-use regardless of the actual contents of the DU. For example, suppose I have a property called RequestInfo, which is a union defined as: type R...

nhibernate recursive bi-directional many to many association

I Have a class Group like this: public class Group { public int GroupId{get;set;} public string GroupName{get;set;} public IList ParentGroups{get;set;} public IList ChildGroups{get;set;} } I want to generate NHibernate mapping for this and generate schema so that there is a group table and a group association table. Is this possib...

Unable to cast object of type NHibernate.Collection.Generic.PersistentGenericBag to List

Hello there, I have a class called ReportRequest as: public class ReportRequest { Int32 templateId; List<Int32> entityIds; public virtual Int32? Id { get; set; } public virtual Int32 TemplateId { get { return templateId; } set { templateId = value; } } public virtua...

Many-to-many collection mapping in NHibernate

My application is a multi-user podcast aggregator, using NHibernate 2.1 (and .NET 4.0 if that changes anything). I'm also a complete NHibernate n00b. Details of each podcast are only stored once, and Users subscribe to podcasts, so there is a many-to-many mapping between podcasts and users which I have mapped in my database with a Subs...

NHibernate Attributes Mapping List

Hello, I'm a new NHibernate developer. I'm using attributes and not map files and I have configured the application to create the tables automatically. I Have two classes , Group and User. Withing the Group class I have a list of users public class Group { [NHibernate.Mapping.Attributes.Id(Name = "GroupId")] [NHibernate.Mapp...

FluentNHibernate joined-subclass

What is the current method of implementing the joined-subclass structure with FluentNHibernate? By "current", I mean by not using deprecated methods such as JoinedSubClass or AddPart. Thanks! ...

Why is my NHibernate query failing with an IndexOutOfRangeException?

I am using Fluent NHibernate and in certain cases my query is failing with a System.IndexOutOfRangeException. It seems that the issue has to do with the combination of using escaped column name(s) in the mapping and calling CreateSQLQuery().AddEntity(). It works fine if none of the columns need escaping or if I instead use CreateCriteri...

NHibernate query baseclass without left joins to derived classes

Hi I have two c# classes one of which inherits from the other. Im trying to use NHibernate to map these classes such that I can query both as efficiently as possible. The base class is not abstract and needs to be able to be queried in its own right. The base class looks somthing like this. public class Cat { public int Id { get; se...

Is there a way to define reusable properties to n-hibernate mappings?

I have a scenario that i want to add some standard properties to my entities. Meaning that i will have e.g. 1 int and 2 string properties applied to all relevant entities. I have over 100 mapping files and most but not all will be hosts to these new properties. In the classes its easy to define this; in the mappings however i've found no...

Ordered many-to-many relationship in NHibernate

Let's say I have two classes: Item and ItemCollection, where ItemCollection contains an ordered list of Item objects with an index, i.e. the list is ordered in a way specified by the user. Let's also say that they have a many-to-many relationship, an ItemCollection can contain many items and an Item can belong to several ItemCollections...

Fluent NHibernate table per class hierarchy multiple tables mapping problem

Hello! I've got a problem with fluent nhibernate table per class hierarchy mapping. I've got 2 domain objects, container (baseclass) and album (subclass). Album only contains a constructor. Container dervies from EntityWithTypedId from Sharp Architect. EntityWithTypedId provides the key of type Guid (the name is ContainerId). public cl...

What is the correct way to define many-to-many relationships in NHibernate to allow deletes but avoiding duplicate records

Hi, I've been fighting with an NHibernate set-up for a few days now and just can't figure out the correct way to set out my mapping so it works like I'd expect it to. There's a bit of code to go through before I get to the problems, so apologies in advance for the extra reading. The setup is pretty simple at the moment, with just thes...

Fluent NHibernate mapping a composite ID from inherited composite IDs

Let's say I have an existing database with the following 3 tables: Table1: (PK)T1ID1 (PK)T1ID2 Table2: (PK)T2ID1 Table3: (FK)T1ID1 (FK)T1ID2 (FK)T2ID1 (Where the 3 keys come from the tables above) My question is: How do I map Table3 with Fluent NHibernate? What is confusing to me is what to do about the fact that its composite keys c...

Fluent NHibernate AutoMapping with discriminator

I'm trying to map inheritance with discriminator, but subclasses don't have discriminator value. How to solve it using AutoMappings? Domain objects are as following: public abstract class Item : GuidIdentityEntity { public virtual string Name { get; set; } } public class Product : Item {} public class RawMaterial : Item {} Config...

How can an indexed many-to-many set be mapped in NHibernate?

Consider an entity, Entry, that contains a collection of another entity (many-to-many), Category, such that the Entry can be associated with a given Category no more than once (implying a "set" and constrained by the database) and the ordering of the Category entities within the collection is fixed and is defined by an extra field on the...