nhibernate-mapping

FluentNHibernate Where clause does not appear to be used when populating collections

I use a Where clause in my FluentNHibernate mappings as follows: public class FooMap : ClassMap<Foo> { public FooMap() { Table("MySchema.Foos"); Where("Deleted = 0"); etc etc } } This where clause gets appended to the SQL when I load individual Foo instances through session.Load<Foo>(1) and when I use LINQ queries. H...

Can NHibernate use internal types?

Hello, I'm a little bit of an NHibernate noobie, and I was wondering if NHibernate can work with internal types. I have a project with a bunch of internal entities, and I would like to use NHibernate within the project to access my data store. If I put the mapping files in the same assembly (or is this even necessary?), will NHibernate...

Why one-to-many does not work as expected in NHibernate?

I have very simple situation and really don't have a clue why this isn't working. This is my schema: **[item]** id (PK) symbol **[item_version]** id (PK) item_id (FK->ITEM) symbol These are my mappings: item.hbm.xml <class name="Core.Model.Entities.Item, Core.Model" table="item" lazy="false"> <id name="Id" column="id" type="lo...

does it make sense to cascade "up" to owners in belongsTo relationship?

I have a Skill class, which hasMany RoleSkills. I have a RoleSkills class which belongsTo Role and Skill I have a Role class which hasMany RoleSkills For Role, I have a mapping that cascades operations to RoleSkills. The question is, does it make sense for RoleSkills to "cascade" back to Skill? I basically want to have a RoleSkill cr...

upgrade to NHibernate 3.0.0.1002, Table is not mapped

Yesterday, I upgraded my NHibernate application from 1.2 to 3.0. I get the following exception c.SubContractors is not mapped [SELECT count(distinct c) FROM CallUp c, c.SubContractors sc Where sc.id = :id AND c.ChildCallUp IS NULL AND c.State > 0 AND (:start_date BETWEEN c.ContractStartDate AND c.ContractEndDate OR :end_date BETWEEN c.C...

NHibernate many-to-many mapping to existing objects

I'm having some issues with a many-to-many relationship I am trying to create. The goal is to save a customer and which products they are allowed to purchase. The products are not unique to a customer and will ALWAYS exist in the database before we try to associate a customer to them. My mapping for the association currently looks lik...

Implementing new NHibernate type for POINT postgresql data type (or any COLUMN of a non-primitive analogous nhibernate type)

Hi everyone. I have a problem with NHibernate and the postgresql POINT data type (although I believe this is a common problem for all of those trying to map a SQL TYPE that is not covered by NHibernate SqlTypes). My Data.Point class has two public floats: xcoordinate and ycoordinate. My first attempt was trying to implement the IUserTy...

Fluent NHibernate Mapping - State Pattern

Hi, I'm not too hot on NHibernate / FNH Mapping but I am looking at implementing the state pattern and like the idea of Derick Bailey's article here: I beleive this was a while ago so the mapping code is out of date, can someone give me a hand to update it for FNH 1.1? public class OrderStatusMap: ClassMap<OrderStatus> { public Ord...

Hibernate bag with multiple elements

I have a bag whose structure looks like this: <bag name="foo" fetch="select" table="table_of_foos"> <key column="foo_ids"/> <many-to-many class="Bar" column="bar_ids"/> </bag> My "table_of_foos" table has two columns: "foo_ids" and "bar_ids", neither of which is unique. I want to add another column to this table that holds som...

Nhibernate class mappings

Question: I have the below nHibernate mapping via attributes. Now I want to create T_lsDomains with a dynamic table prefix. Such as TBL_lsDomains or just lsDomains. Is there any way I can do this with attributes? Since they are defined at compile time, and must be constant? Is there any way to do this? Or can fluentNhibernate do thi...

Mapping the flip side of an NHibernate <any> association

Ayende has a great example of using the <any> mapping here, which I am reposting as part of my question since comments are closed on that blog post. Given his original mapping: <class name="Order" table="Orders"> <id name="Id"> <generator class="native"/> </id> <any name="Payment" id-type="System.Int64" meta-type=...

Is there a trick to correctly defining version properties in NHibernate?

I am trying to use NHibernate to map a legacy database which uses a decimal(9,0) (~32 bit integer) "version property" (for optimistic locking of each row). The fields are declared nullable in the database, and in section 5.1.7 of the NHibernate reference manual it states: Version numbers may be of type Int64, Int32, Int16, Ticks, Ti...

Nhibernate mapping of System.Drawing.Image

Question: I get an exception serializing this class to a nHibernate xml file ({"Could not determine type for: System.Drawing.Image, System.Drawing, for columns: NHibernate.Mapping.Column(Settings)"}). How to map System.Drawing.Image to nHibernate ? And what MS-SQL dbtype is to be used? using System; using System.Collections.Generic; us...

How to avoid unnecessary joins in NHibernate

Hi, I've got a class named 'Entity', which can be individuals or organizations. I have a few other classes that are descendants of Entity, which have their properties defined in extension tables in my database. One of my descendants is named 'User'. A really truncated example of my table structure: Table: ENTITY Id - UniqueIdentifie...

NHibernate: Is it possible to use stored proc when updating/deleting/inserting a class mapped on view?

Here is the preamble: I have a SQL View and mapped NHibernate C# class I only allowed to modify SQL View data through some stored procedures (Insert/Update/Delete) How to denote such logic in mapping file? Is it possible with only specific mapping or i need some supplementary code? ...

can you re-use nhibernate mapping files for tables with common columns

We have a bunch of lookup tables that all share the same columns (ID,Code,Description, etc) and my co-worked just asked me if we could build a generic lookup.hbm.xml mapping file and use it as a base for all the other lookup tables. Does nhibernate support include files, or some other way to reference a common chunk of XML? I understan...

Remove from one side of the many to many in Nhibernate

Hi there, I have these 2 objects in NHibernate forming a many to many relationship: User: <?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Providers" namespace="Providers.Objects"> <class name="User" table="Users"> <id name="UserId" type="int"> <ge...

How do I get NHibernate to save an entity if I assign it an ID, but generate one otherwise?

According to the REST philosophy, a PUT request should update the resource at a URL if it exists, and create it if it doesn't exist. So in other words, if I use the following URL: PUT http://server/item/5 If an Item exists with an ID of 5, it will be updated. If an Item doesn't exist with an ID of 5, a new Item will be created with an...

NHibernate/Hibernate define mapping without a class

I have a particular case where I need to define a query including a table ASpecialTable for which I don't have any mapping or business class defined. However, the return type of the query is an existing business class MyBO. For that particular table, I'll never need it in my code, and it doesn't contain a primary key, or to be short: I...

Need help for my NHibernate mappings

Hello all, I have the following (simplified) mappings: public class RosterMap : ClassMap<Roster> { public RosterMap() { References(tr => tr.Team) .Not.Nullable(); HasMany(r => r.Players) .Inverse() .Cascade.AllDeleteOrphan(); References(roster => roster.Match) ...