nhibernate-mapping

Fluent nHibernate automapping property as nvarchar(max)

using fluent nhibernate, and automappings (nhibernate creates my db schema), how can i get nhibernate to create a nvarchar(max) column in the database based on the following class public class VirtualPage : BaseEntity { public virtual int ParentId { get; set; } public virtual string PageName { get; set; } public virtual stri...

How do I specify the name of the PK in the subclass table when using SubClass in FluentNHibernate?

I am attempting a subclass mapping in Fluent NHibernate. In the parent class mapping, I have to specify the ID column name to prevent FNH guessing incorrectly: Id(x => x.Id).Column("UserId"); I also need to specify the ID (or foreign key if you like) field name in the subclass mapping, since FNH is guessing that incorrectly too. How ...

NHibernate transactions not closing

Out of interest of learning what's going on behind the scenes, I am running some test methods that specifically dump data to my database via NHibernate. I'm toying with various mapping settings and am watching the session processes via the latest version of NHProfiler. I'm noticing something odd, and it may not be of concern, but thoug...

NHibernate navigators mapped to the part of a composite key problem - legacy database usage

We have a legacy database that we cannot change. And we are trying to move to the NHibernate instead of old DataAccess layer which is a garbage and is too slow. it has tables like these: GPI table has (PU_ID, PAR_ID, Data, Data2) columns BLOCK table has (GA_ID, Data, PAR_ID) columns COMPANY table has (PU_ID, Data) columns I had create...

FluentNHibernate. I need to map a hasmany relationship to a joined subclass entity type

Hi, I am trying to get this FluentNHibernate mapping to work. I have three tables Person, Employee and Employer. The Employee table extends the attributes of the Person table, and it's primary key is a foreign key to the Person table. The Employee table also has a foriegn key to the Employer table. An employer can have many employees, a...

How can I create a Fluent NHibernate Convention that ignores properties that don't have setters

I'm looking for a FluentNH (Fluent NHibernate) convention or configuration that ignores all properties that have no setter: It would still map these: public class foo{ public virtual int bar {get; private set;} } And omit these: public class foo{ public virtual int fizz{get;private set;} public virtual int bar{get {return fizz...

How do I write this condition into an NHibernate HBM mapping?

So I'm on an NHibernate crash course, and kinda hit a snag with the example below. Suppose I have the following .NET class: class A { int id; int type_var; List<B> someCollection; } class B { int id; string someText; } I'll probably map it like : <class name="A" table="A"> <id name="id" type="Int32"> ...

NHibernate/SQL Server multiple foreign keys to same table... Possible?

Hi, I have a SalesOrder table and a separate Address table. The SalesOrder has two addresses - thus avoiding use of a list, there are the Delivery and Invoice address. This is how they have been mapped in the SalesOrder mapping file: <many-to-one name="DeliveryAddress" class="Address" column="`DeliveryAddressGUID`" /> <many-to-one na...

NHibernate mapping with an intermediate table

I am new to NHibernate and am running into some issues with mapping. Lets say I have a table: People PersonID PersonName PersonAge Then I have another table ParentRelaitions RelationID Parent (This is a PersonID) Child (This is also a PersonID) What I really want to get out of this is an object like this public class Person { s...

How to map a read only property backed by a query in Hibernate

I'm wondering how to best implement a property (here, LatestRequest) which is read-only, backed by a query. Here, I have an Export, which can be requested to happen multiple times. I'd like to have a property on the Export to get the latest ExportRequest. At the moment, I've got a many-to-one mapping with a formula, like this: <class ...

FluentNHibernate blows up in Windows Service but not website

I've got a class library doing all my NHibernate stuff. It also handles all the mapping using Fluent NHibernate - no mapping files to deploy. This class library is consumed by a number of apps, including a Windows Service running on my computer. Although it works fine in all my web apps, the Windows Service gets this when it tries to us...

NHibernate: map multiple columns into a single collection

Suppose I have a table: ID(pk) | HOME_EMAIL | WORK_EMAIL | OTHER_EMAIL ------------------------------------------------- and the .NET classes class A { int id; List<MyEmail> emails; } class MyEmail { string email; } I suppose there's no way to map those (multiple) columns into a single collection in NHibernate, or is ...

Fluent Nhibernate - dont understand the generated Sql from NHibernate

hi, i created the following mappings with fluent nhibernate: public class AuswahlMap : ClassMap<Auswahl> { public AuswahlMap() { Table("AUSWAHL"); Id(x => x.Id,"ID") .GeneratedBy.Sequence("SEQ_AUSWAHL"); Map(x => x.Programm).Not.Nullable();; Map(x => x.Variante); Map(x => x...

Fluent HNibernate Mapping Property Issue

Hi, i have two entities one called User and another called Membership which has a one to many mapping from User to Membership. I need to add a property on my User entity called CurrentMembership which gets the latest Membership row (ordered by the property DateAdded on the Membership Entity). I'd appreciate it if someone could show me ...

How get correct Exception from ADO.NET about foreign key violation

I would like to get correct Exception from ADO.NET about foreign key violation. Is there a way to do that? I am using try to catch ADO.Exception and check it message text for 'foreign'. So, if there is 'foreign' text in exception text, it is a violation and I can alert. Is it the right way to do or any other method? try{ base.De...

NHibernate - Delete Not Peristing in the Database

Hi, i'm trying to remove an item from a one to many list and have it persist in the database. Here are the entities i have defined: public class SpecialOffer { public virtual int SpecialOfferID { get; set; } public virtual string Title { get; set; } public virtual IList<SpecialOfferType> Types { get; private set; } pub...

NHibernate: mapping user type object to a separate table

Let's start with this mapping: <component name="Location"> ... <property name="Settings" type="JsonUserType,..."> <column name="LocationSettingsType" /> <column name="LocationSettingsData" /> </property> </component> This maps to TABLE Primary ( ... LocationSettingsType, LocationSettingsData ... ) and ...

Having trouble with Nhibernate and ManyToOne properties

I have a class that has a many to one property defined as follows: [NHMA.ManyToOne(Name = "TypeOfEvent", ClassType = typeof(EventType), Column="EventTypeId")] public virtual EventType TypeOfEvent {get; set;} Everytime I try to load the class using a simple query (just loading all of the events in the database) I get the following exce...

Fluent Nhibernate: Mapping single entity with interface requirements

Good afternoon. Before I begin my explanation, I have had a look at other similar questions but the subtle differences (mainly in purpose of design) mean that the solutions provided in these answers to not apply to me. I am attempting to create a 'Base data access library' for use with future projects so that I do not have to spend my ...

nhibernate to save only required properties

Hi, I'm using NHibernate 2.2 for my database work and I've faced an issue recently. I have a class called PrescDrugItem which is shown below public class PrescDrugItem { public virtual int ItemNumber { get; set; } [DataMember] public virtual int AmountIssued { get; set; } [DataMember] public virtual string TimePer...