nhibernate-mapping

How to map an IDictionary<String, CustomCollectionType> in NHibernate

Very close to what I'm trying to do but not quite the answer I think I'm looking for: How to map IDictionary<string, Entity> in Fluent NHibernate I'm trying to implement an IDictionary<String, IList<MyEntity>>and map this collection to the database using NHibernate. I do understand that you cannot map collections of collections directl...

NHibernate: How to test a many-to-one relationship is lazy?

I've got a simple many-to-one relationship (an Order has a Customer who placed it). Here's the except from my Order mapping: <many-to-one name="Customer" column="FK_CUSTOMERS" class="MyApp.Customer, MyApp" not-null="true" lazy="proxy" cascade="none" /> Yet the following does not pass: configuration.GetClassMapping(typeof(Order)) ...

How do I tell NHibernate to load a component as not null even when all its properties are null?

Hi, I have a Date class which wraps over the DateTime? class (aids in mocking DateTime.Now, our domain ,etc). The Date class class only has one protected property : DateTime? date public class Date { protected DateTime? date; } // mapping in hbm <component name="CompletedOn"> <property column="StartedOn" name="date" access="fie...

NHibernate, VS 2010

Здравствуйте, ANRY! Совсем недавно при прохождении практики от университета, столкнулся с NHibernate. Тут же прочитал вашу статью "Hello NHibernate!". Понадобилось реализовать некое подобие магазина: то есть, есть товар, клиент, заказ. Соответственно создал 4 таблицы в MSSQL 2010: Товар(id_товара, название, цена), Клиент(id_клиента, имя...

How to configure a generic component with FluentNHibernate ?

Here is the component for which I want to configure mapping public class Range<T> : ValueObject { public virtual T Start {get; set;} public virtual T Finish {get; set;} } In my domain I have many entities which have properties like Range < DateTime>, Range < int > ... for a particular class with property x we configure the c...

NHibernate: completely overriding base domain entity

I have a situation where I have a Common.Domain.Person and Specific.Domain.Person. First one should be provided as a part of a common package. Second one appears when common package has to be customized to fit the needs of specific project. In the object model, it can be easily implemented with inheritance. In the NH mapping, however...

With NHibernate, how can I add a child object when updating a parent object?

I have a simple Parent/Child relationship between a Person object and an Address object. The Person object exists in the DB. After doing a Get on the Person, I add a new Address object to the Address sub-object list of the parent, and do some other updates to the Person object. Finally, I do an Update on the Person object. With a SQL...

How can I eager-load a child collection mapped to a non-primary key in NHibernate 2.1.2?

Hi, I have two objects with a many-to-many relationship between them, as follows: public class LeftHandSide { public LeftHandSide() { Name = String.Empty; Rights = new HashSet<RightHandSide>(); } public int Id { get; set; } public string Name { get; set; } public ICollection<RightHandSide> Right...

How to find unmapped properties in a NHibernate mapped class?

I just had a NHibernate related problem where I forgot to map one property of a class. A very simplified example: public class MyClass { public virtual int ID { get; set; } public virtual string SomeText { get; set; } public virtual int SomeNumber { get; set; } } ...and the mapping file: <?xml version="1.0" encoding="utf...

NHibernate - Saving simple parent-child relationship generates unnecessary selects with assigned id

Entities: public class Parent { virtual public long Id { get; set; } virtual public string Description { get; set; } virtual public ICollection<Child> Children { get; set; } } public class Child { virtual public long Id { get; set; } virtual public string Description { get; set; } virtual public Parent Parent ...

many-to-one with multiple columns

I have a legacy data base and a relation one-to-one between two tables. The thing is that relation uses two columns, not one. Is there some way to say in nhibernate that when getting a referenced entity it used two columns in join statement, not one? I have a similar table structure TaskProgress ProgressId TaskId AssignmentId UserId ...

Inherited fluent nhibenate mapping issue

I have an interesting issue today!! Basically I have two classes. public class A : B { public virtual new ISet<DifferentItem> Items {get;set;} } public class B { public virtual int Id {get;set;} public virtual ISet<Item> Items {get;set;} } The subclass A hides the base class B property, Items and replaces it with a new proper...

How do you map the identity column in the results of a stored procedure?

We're using NHibernate.Mapping.Attributes to do our mappings. In order to get NHibernate to populate a data object automatically, it appears that you need to allow for an identity column. Okay, no problem, I added a (fake) PK column to my stored procedure results (it's a report query, so the identifier doesn't need to mean anything as l...

NHibernate.PropertyValueException : not-null property references a null or transient

I am getting the following exception. NHibernate.PropertyValueException : not-null property references a null or transient Here are my mapping files. Product <class name="Product" table="Products"> <id name="Id" type="Int32" column="Id" unsaved-value="0"> <generator class="identity"/> </id> <set name="PriceBrea...

Fluent NHibernate join table mapping

Reverse engineering an existing database to map with N-Hibernate using Fluent N-Hibernate. How can I map this? Address table Id Address1 Address2 Person table Id First Last Types Id TypeName PersonAddress table (A person can have home, business etc addresses) Id PersonId (Id from person table) AddressId (Id from addre...

Strategies for Mapping Views in NHibernate

It seems that NHibernate needs to have an id tag specified as part of the mapping. This presents a problem for views as most of the time (in my experience) a view will not have an Id. I have mapped views before in nhibernate, but they way I did it seemed to be be messy to me. Here is a contrived example of how I am doing it currentl...

NHibernate mapping one table on two classes with where selection

We would like to map a single table on two classes with NHibernate. The mapping has to be dynamically depending on the value of a column. Here's a simple example to make it a bit clearer: We have a table called Person with the columns id, Name and Sex. The data from this table should be mapped either on the class Male or on the cla...

One-to-one Mapping issue with NHibernate/Fluent: Foreign Key not updateing

Summary: Parent and Child class. One to one relationship between the Parent and Child. Parent has a FK property which references the primary key of the Child. Code as follows: public class NHTestParent { public virtual Guid NHTestParentId { get; set; } public virtual Guid ChildId { get { return ChildR...

how to delete fk children in nhibernate

I would like to delete the ICollection PriceBreaks from Product. I'm using the following method. However they dont seem to delete. What am i missing. When i step thru. i notice that "product.PriceBreaks.Clear();" doesn't actually clear the items. Do i need to flush or something? public void RemovePriceBreak(int productId) { using (...

Manually setting the ID

I have a Users table where the "ID" field is a GUID field. Using ASPNET I am creating a user account and getting the GUID back. I am trying to create associated records in my tables with that GUID as the main ID. The problem I am running into is that when I manually set Users.ID NHibernate tries to do an Update, not an Insert. I see ...