nhibernate-mapping

Discriminator based on joined property

Suppose I have this relationship: abstract class Base { int Id; int JoinedId; ... } class Joined { int Id; int Discriminator; ... } class Sub1 : Base { ... } class Sub2 : Base { ... } for the following tables: table Base ( Id int, JoinedId int, ... ) table Joined ( Id int, Discriminator int, ... ) I would like to set up a table-per...

NHibernate Many-to-many with a boolean flag on the association table

Hi I am doing some work on an application that uses an existing schema that cannot be altered. Whilst writing my NHibernate mappings I encountered a strange many-to-many relationship. The relationship is defined in the standard way as in this question with the addition of a boolean flag on the association table that signifies if the rel...

Does it matter which side of a bidirectional many-to-many relationship you set as inverse in NHibernate?

Simple question: does it matter which side of a bidirectional many-to-many relationship you set as the inverse in NHibernate? And if so, what are the implications of setting it on one end vs. the other? Some more clarification: I'm setting both sides of the relationship: Parent.Children.Add(child); Child.Parents.Add(parent); In a cas...

problem with mapping table in NHibernate

Hey, I rewrite application from ASP.NET to Silverlight and use NHibernate 2. Tables in my db looks like this: In Dziecko table I have reference to id of Opiekun and Grupy. In ASP it's ok for me but in videos Summer with NHibernate I see that Stephen Bohlen in exchange use object of this type, for me its Opiekun and Grupy.But in SQL Se...

Fluent NHibernate mapping IList<Point> as value to single column

I have this class: public class MyEntity { public virtual int Id { get; set; } public virtual IList<Point> Vectors { get; set; } } How can I map the Vectors in Fluent NHibernate to a single column (as value)? I was thinking of this: public class Vectors : ISerializable { public IList<Point> Vectors { get; set; } /* H...

how to map SubclassMap and HasManyToMany in Fluent NHibernate

Hi everyone. My problem is fluent nhibernate mapping a many to many relationship, they end up referencing a non existent Id. public UserMap() { Id(x => x.Id); Map(x => x.Name); Map(x => x.Password); Map(x => x.Confirmed); HasMany(x => x.Nodes).Cascade.SaveUpdate(); HasManyToMany<Node>(...

Many to Many mapping problem - Child Collection always empty

I have the following situation. I have a Movie object which contains a list of characters, and the characters each have an person (actor). Additionally, I want the actor objects to contain a list of characters. I've set up my mappings in fluent-nhibernate, and everything seems to be working perfectly, except that the Person.Characters...

NHibernate Custom HQL for loading

The following is from the NHibernate documentation: 15.4. Custom SQL for loading You may also declare your own SQL (or HQL) queries for entity loading: <sql-query name="person"> <return alias="pers" class="Person" lock-mode="upgrade"/> SELECT NAME AS {pers.Name}, ID AS {pers.Id} FROM PERSON WHERE ID=? FOR UPDATE </s...

NHibernate set : Should I override Equals and GetHashCode ?

I am new to NHibernate. I am using <set ... > mapping for some many-to-one and many-to-many associations. These are exposed as properties of type ICollection<T>, in practice implemented by HashSet<T>. My question is, should I override Equals and GetHashCode for the related types, so they match the database identity of the types (in pra...

How do I change a child's parent in NHibernate when cascade is delete-all-orphan?

I have two entities in a bi-directional one-to-many relationship: public class Storage { public IList<Box> Boxes { get; set; } } public class Box { public Storage CurrentStorage { get; set; } } And the mapping: <class name="Storage"> <bag name="Boxes" cascade="all-delete-orphan" inverse="true"> <key column="Stora...

Generating nHibernate cfg file from Configuration instance

Is there any way for me to generate an nHibernate configuration file from a Configuration instance (that has been already configured by some external code?). I'm looking for an easy way to mimic this external code with a static XML file? (I guess similar to the "ExportTo" method that Fluent nHibernate has for fluent mappings - but actin...

In NHibernate (Fluent), How do you map a property on referenced object into parent object?

I want to map the Name column from the Child table into the Parent object. How do you do this (using Fluent NHibernate)? public class Parent { public int Key { get; set; } public string ChildName { get; set; } } Tables +--------------+ +------------------+ | Parent | | Child | +--------------+...

nhibernate mapping attributes vs fluent nhibernate

Do mapping attributes offer the same versatility as nhib hbm's do? Can you use them together with FNH to handle things FNH doesn't yet do as well as hbm's can? Cheers, Berryl By mapping attributes, I don't mean hbm files; there are apparently attributes that come with NHib (or maybe NHib contrib these days) that you use to decorate you...

FluentNhibernate many-to-many mapping - resolving record is not inserted

Hi, I have a many-to-many mapping defined (only relevant fields included) with FluentNHibernate (v1.0.0.637): // MODEL: public class User : IPersistentObject { public User() { Permissions = new HashedSet<Permission>(); } public virtual int Id { get; protected set; } public virtual ISet<Permission> Permissions { ...

Hibernate mapping for composite primary key and auto increatement

Pls Provide me mapping for the following table CREATE TABLE adregistrationtbl ( NUM_ID int(20) NOT NULL auto_increment, openingDate date default NULL, purchaserName varchar(50) default NULL, purchaserAddress text, nomineeName varchar(50) default NULL, nomineeRelation varchar(25) default NULL, nomineeAge varchar(3) default ...

NHibernate Transforms and mapping

I have a stored proc that returns me a set of data and I am using the DistinctRootEntityResultTransformer to return that data as a tree. You can see an example of this here: http://ayende.com/Blog/archive/2009/08/28/nhibernate-tips-amp-tricks-efficiently-selecting-a-tree.aspx Is there a way to specify this in the mapping instead of wi...

FluentNHibernate: multiple one-to-many relationships between the same entities.

Hi, I'm working on a bug tracking application. There are tickets, and each ticket has an opener user and an assigned user. So, basically, I have two entities, which have two many-to-one relationships with each other. Their schematic is this: User: public class User { public virtual int Id { get; protected set; } ... publi...

Fluent Nhibernate and hbms

As an FNH user, do you find you sometimes need to supplement FNH with an hbm file? Any relatively common edge cases where you do, if so? Cheers, Berryl ...

(N)Hibernate: deleting orphaned ternary association rows when either associated row is deleted.

I have a ternary association table created using the following mapping: <map name="Associations" table="FooToBar"> <key column="Foo_id"/> <index-many-to-many class="Bar" column="Bar_id"/> <element column="AssociationValue" /> </map> I have 3 tables, Foo, Bar, and FooToBar. When I delete a row from the Foo table, the assoc...

How to map it? HasOne x References

Hi everyones, I need to make a mapping One by One, and I have some doubts. I have this classes: public class DocumentType { public virtual int Id { get; set; } /* othes properties for documenttype */ public virtual DocumentConfiguration Configuration { get; set; } public DocumentType () { } } public class D...