nhibernate-mapping

NHibernate won't delete orphaned object

Hi everyone, I have a few classes that look like this public class Token { public int Id { get; set; } public ITokenInstance Instance { get; set; } } public interface ITokenInstance { int Id { get; set; } Token Token { get; set...

Mapping NHibernate Many-to-Many

Hey all, I am trying to map a legacy database here and I'm running into a problem. In my schema I have a concept of Modules and a concept of Variables. Each Module consists of one or more Variables and each of these Variables has properties specific to that Module. A Varable sits on a Relation. Based on the classes below what is the b...

NHibernate Map many-to-many join table

My database structure looks something like this: Person Id Name FieldA FieldB Phone Id Number PersonPhone PhoneId PersonId IsDefault My NHibernate mappings for the Person and Phone objects are straight forward, its the PersonPhone I'm having difficult with. I want to have a collection of PersonPhone objects as a pr...

Mapping Dictionarys containing a List

Hello, I'm trying to map a Dictionary containing Lists. I have the following set of tables: CREATE TABLE Item(id) CREATE TABLE Filter(id) CREATE TABLE FilterType(id) CREATE TABLE ItemFilter( item REFERENCES Item(id), filter REFERENCES Filter(id), filterType REFERENCES FilterType(id) ) and I want to do this mapping: class Item...

nHibernate: Saving new parent object while creating a child object

I am trying to save a record which has a many-to-one property mapping. I attempt to assign a newly created parent object here (or use an existing, but that works fine) but I get an error when it tries to add the ID of the parent object to the child's table. Saying it cannot add NULL to the table, which is true, but I thought nHibernate w...

NHibernate "database" schema confusion [.\hibernate-mapping\@schema]

I'm using NHibernate primarily against an MSSQL database, where I've used MSSQL schemas for the various tables. In my NH mapping (HBM) files, I've specified the schema for each table in the mapping as follows: <?xml version="1.0"?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true" ...

nhibernate many-to-many mapping - additional column in the mapping table?

hi I have following mapping definitions: <class name="Role" table="Role" optimistic-lock="version" > <id name="Id" type="Int32" unsaved-value="0" > <generator class="native" /> </id> <property name="RoleName" type="String(40)" not-null="true" /> <bag name="UsersInRole" generic="true" lazy="true" cascade="all"...

NHibernate - LazyLoad one-to-zero

Hi Iam struggling with NHibernate and its lazyload. I have a structure which I simplified but it show my issue. Class Shift { int ShiftID; DateTime ShiftStart; Employee Employee; } Class Employee { int EmployeeID; string Name; } Data: ShiftData ID SHIFTTIME EmployeeID (int) 1 ...

NHibernate - Incorrect thinking? Subclassed Model based on Join

I have a simple model class (Part), which pulls from it's information from a single table (t_Part). I would like a subclass of this model called (ProducedPart), that would still utilize NHibernate's caching mechanisms, but would only be instances of (Part) that have a foreign key relationship in a table called "t_PartProduction". I do ...

How to map a foreign key column in nhibernate?

Actually, the question is more complex than as it is described. I am newbie on nhibernate and I want to map a table with foreign key columns. In most of nhibernate samples the foreign key column assignments are generally implemented by setting the referred entity. I mean, If I have a CategoryId column then I need a Category property and ...

defining enum types in a mapping file, or columns from another table

Hi, if my mapping file, how would I reference a C# enum type? what about columns from another table? ...

How to make Nhibernate generate table with Text field instead of nvarchar(255)

I'm trying to make NHibernate generate my schema/SQL 2008, and using the mapping below it keeps wanting to create an nvarchar(255) column instead of text...any ideas? <property name="AnnouncementText" column="AnnouncementText" type="StringClob"> <column name="AnnouncementText" sql-type="NTEXT"/> </property> Thanks! ...

nhibernate - delete throws "deleted object would be re-saved by cascade"

hi i have following model: <class name="Person" table="Person" optimistic-lock="version" > <id name="Id" type="Int32" unsaved-value="0" > <generator class="native" /> </id> <!-- plus some properties here --> </class> <class name="Event" table="Event" optimistic-lock="version" > <id name="Id" type="Int32" u...

Nhibernate mapping: Encapsulating a list within an object.

I have two tables Deal and Cost. Costs can be of a number of types, eg Planned, Unplanned. Every deal can have one an only one of each type of cost. This is easy enough to map as a many-to-one on deal, reulting in an IList of Costs. But what I want is to create a costs object that has named properties for each cost. So that for a databas...

Querying unmapped properties in nhibernate

I am working with Linq-To-NHibernate. I need to use some properties that is not mapped to columns. For example Repository<Person> .Find() .Select(p => new PersonModel() { Id = p.Id, FullName= p.FullName,Position = p.Position }); The position is not a mapped property, it contains some logic. I got unmapped property error. Thank...

How to Map Enum in NHibernate to Properly Create DB Field on Schema Export?

I've seen several questions related to properly mapping an enum type using NHibernate. This article by Jeff Palermo showed me how to do that properly by creating a custom type. I use Schema Export to create my DB during my dev cycles, but this method breaks my export statement. Is there a way to specify the type of the column on export?...

Time and Nhibernate

hello i got an application that uses nhibernate as orm, i need to store data that represents time, whats the best way to do it? nhibenate dont know to convert time field from db to a timespan, only string. ...

Map a property to the latest entry in NHibernate

Let's say my domain looks like this: I have an object, Vehicle, that has an OdometerReading property. An OdometerReading has the Miles & Date (when it was read). I need to keep a history of all OdometerReadings for the Vehicle in the database, but don't want the entire odometer history to belong to the Vehicle object. What I wou...

Fluent NHibernate Has Many to Many Convention Questions

I am new to fluent nhibernate and nhibernate. I want to write a fluent nhibernate autopersistence convention to handle creating the many to many mappings for my entities. This is what I have right now: using System; using FluentNHibernate.Conventions; using FluentNHibernate.Mapping; namespace Namespace { public class HasManyToMan...

Mapping files generation with nhibernate

i m new to nhibenate and i really find it painful to write the entire mapping files is there a tool or a vs addin that helps you do the mapping ? thx for your time :) ...