nhibernate-mapping

Why is NHibernate doing an UPDATE rather than an INSERT?

Continuing my explorations in NHibernate with my podcast application, I've come across something odd: NHibernate is UPDATEing when I would expect an INSERT. The situation is a simple one-to-many relationship between a podcast and its items. Here's my NHibernate mapping: <hibernate-mapping assembly="App.DataModel"> <class name="Feed"...

Nhibernate : How to map tow same-structure tables to a entity class

I encountered the following troubles: i have two table that have same structure: t_collectingResult_live and t_collectingResult_history, i need to operate them in a same session and i don't think i have to define two entity classes with same structure, but i found that switch the NHibernate.Mapping.PersistentClass.Table.Name between "...

NHibernate "Errors in named queries"

I have the following named SQL query defined: <sql-query name="ItemSearch"> <return class="ItemSearchResult"> <return-property name="Item" column="ItemId" /> <return-property name="Distance" column="Distance" /> </return> SELECT Items.*, dbo.DistanceBetween(Latitude, Longitude, :lat, :long) AS...

How can I use Fluent NHibernate Automapping with multiple Lists of the same type in an Entity?

It appears that NHibernate cannot automap more than one IList of a given type in an entity. Consider the following two entities (based on the Examples.FirstProject sample code that is included with the Fluent NHibernate source code). public class Employee { public virtual int Id { get; private set; } public virtual string Fir...

How do I exclude a base class using fluent mappings in Fluent NHibernate?

I have an abstract base class, Entity, that all my POCOs derive from: public abstract class Entity { public virtual Guid Id { get; set; } } And the mapping file: public class EntityMap<T> : ClassMap<T> where T : Entity { public EntityMap { Id(x => x.Id); } } This way, I don't have to write Id(x => x.Id) in e...

NHibernate "illegal access to loading collection" error

What is the reason of this error? My class is Course and it has notes. Mapping is as below. Any idea? <bag name="Notes" table="NOTE" cascade="all"> <key column="COURSEID"/> <one-to-many class="Server.Data.Note, Server.Data"/> </bag> ...

NHibernate.Mapping.Attributes.Filter

Hello people! I'm mapping my database tables using NHibernate with NHibernate.Mapping.Attributes library and I got stuck to get the Filter attributes to work. Suppose a class A that has a set of objects of class B. So, I have, the following: [NHibernate.Mapping.Attributes.Set(0, Inverse = true, Lazy = NHibernate.Mapping.Attributes.Coll...

NHibernate Many to One / One to One with differing keys

Hey all, I'm kicking the tires on NHibernate and have a conoundrum I have been scratching my head over for a bit now, working with a legacy database with some fairly complex relationships. ClaimRoot has a primary key of a claimGUID. ClaimRoot has a bag of Claimdetails associated by claimGUID (this works a treat). The problem is that C...

Updating all rows of a denormalized table in NHibernate

Hey all, quick NHibernate question. In my current project, we have a denormalized table that, for a given unique header record, will have one or more denormalized rows. When the user is accessing a POCO representing the header and performs an update, I need this change to cascade down to all of the denormalized rows. For example, if ...

NHibernate HasAndBelongsToMany polymorphic association not being respected

Class structure looks like the following: abstract ItemBase - Discriminator [Type] = 0 [PrimaryKey GuidComb] Id ... shared properties Item : ItemBase - [Type] = 1 [HasAndBelongsToMany, Inverse = true, RelationType = Set] -> Documents ... other properties ItemHistory : ItemBase - [Type] = 2 [HasAndBelongsT...

Mapping Generic Classes using NHibernate

I'm trying to do the following, but it's complaining that the "classes referenced by 'extends' were not found". I think I need to having a mapping for each concrete type of Component but I can't specify the Attributes.Class twice.. The code is as follows: [NHibernate.Mapping.Attributes.Class(Table = "Components", Abstract = true, N...

Mapping self-table one-to-many using non-PK clolumns

Hey, i have a legacy DB to which a Person object is mapped, having a collection of family-members, like this: class Person { ... string Id; /* 9-digits string */ IList<Person> Family; ... } The PERSON table seems like: Id: CHAR(9), PK FamilyId: INT, NOT NULL and several other non-relevant columns....

fluent mapping ,map a one to many for best performance

i need to map a one to many relation between something that look like this public class Foo : Bar { //some simple type properties } public class Bar : EntityBase { public virtual IList<Foo> Foos {get;set;} //some simple type properties } i want the best performance.. what is the way it should be mapped and how the table/s ...

NHibernate: Parent list properties and related child properties are not synchronized

I have two related objects: ProgramSession and ProgramTask, with a one-to-many relationship. A ProgramSession has many ProgramTasks. So the objects looks like this: public class ProgramSession { public virtual IList<ProgramTask> ProgramTasks { get { return _programTasks; } set { _programTasks = value; } } } ...

NHibernate self-join many-to-many symmetric relationship (person friends problem)

Is there any way to set-up a symmetric self-join relationship mapping in NHibernate? Suppose we have two tables: Users id Relations id user1 user2 relation_type The User and Relation classes should look like this: class User { public virtual int Id { get; set; } public virtual string Name { get; set; } public ...

Help with attribute mapping my class

My class looks like: public class User { public virtual int ID {get;set;} public virtual string Username {get;set;} } Table: User -UserID INT NOT NULL, -Username NVARCHAR(50) NOT NULL UserID is the PK, IDENTITY. How would I use nhibernate attribute mapping for my class? ...

DDD: Can a Value Object have lists inside them?

I'm not well versed in domain driven design and I've recently started created a domain model for a project. I still haven't decided on an ORM (though I will likely go with NHibernate) and I am currently trying to ensure that my Value Objects should be just that. I have a few VOs that have almost no behavior other than to encapsulate "li...

Error caused by GeneratedBy statement in Mappings when running tests

I am using Fluent NHibernate on a project that has an Oracle 10g database. I am also using SQLite with a schema generated from my mapping for testing. The problem I am having is that, since the primary keys on my tables are generated by Oracle Sequences, to get my Add methods to work correctly I had to add .GeneratedBy.Sequence({sequenc...

Fluent NHibernate Join with Constraint

i have an entity with its properities spread over two tables that i'd like to map to one class using Fluent NHibernate, but with a constraint on the joining table. i've changed the domain of my problem for this question to be the familar 'customer' domain, so my example here may seam a little contrived, but it illustrates my problem. it...

Fluent NHibernate - unit-testing a one-to-many *inverse* mapping

I can't figure out how (or if it's at all possible) to use the Fluent NHibernate PersistenceSpecification<T>.CheckList(...) method to check an inverse one-to-many mapping. Here's what I'm trying to do: Using fluent nhibernate on a vanilla blog/post example, I have defined a one-to-many blog<->posts mapping. One restriction I want is th...