nhibernate-mapping

How do i map this in NHibernate

I Have two classes, Survey and Poll classes. Also I have Question and Question Choice classes. How do I map these so I come out with particular table formats. here is the classes involved. public class Survey { public IList<Question> Questions { get; private set; } } public class Poll { public Question Question { get; set; ...

hibernate mapping file with dependancies to existing tables/POJOs

We have an existing and working database created from hbm mapping files. We want to create some new tables for an optional feature. One option is that these new tables always exist but we would prefer for the tables and POJOs to only be created on request. My issue is that these tables/POJOs have dependancies on existing tables/POJOs....

NHibernate Criteria Type Mismatch

This code ICriteria crit = service.Session.CreateCriteria(typeof (DatabaseVersion)); crit.Add(Restrictions.Eq("Id.Minor", 4)); IList<DatabaseVersion> list = crit.List<DatabaseVersion>(); causes the following error :NHibernate.QueryException: Type mismatch in NHibernate.Criterion.SimpleExpression: Id.Minor expected type System.Int16, a...

How to best design the entity data classes for the following SQL Schema?

I have the following database schema: The issue is how to create the entity data class in Nhibernate? Is this better: public class Store { public virtual int Id { get; private set; } public virtual string Name { get; set; } public virtual IList<Product> Products { get; set; } public virtual IList<Employee> Staff { ge...

Forcing nHibernate to cascade delete before inserts

I have a parent object which has a one to many relationship with an ISet of child objects. The child objects have a unique constraint (PageNum and ContentID - the foreign key to the parent). <set name="Pages" inverse="true" cascade="all-delete-orphan" access="field.camelcase-underscore"> <key column="ContentId" /> <one-to-many c...

NHibernate join single value from other table

I'm trying to get nHibernate to join the name of the structure that is stored in separate table into the structure POCO object. The database looks something like this: +-----------+ +------------+ +-----------+ | Structure | | Texts | | Languages | +===========+ +============+ +===========+ | Id | | Id | | I...

nhibernate: How do I map a component which references an enity?

My db looks somthing like this: MyEntity State ----- ----- id id street name stateId ... zip status ... My Model looks like this: class MyEntity { int id { get; set; } Address location { get; set; } string status { get; set; } // ... } class Address { string street { get; set; ...

NHibernate SchemaExport failing to drop a table .... sometimes

I'm using NHibernate for the DAL of my application, and in particlular NHibernate's SchemaExport function to drop/recreate my database schema before the execution of unit tests. The issue I'm having is that when I run the unit tests and execute SchemaExport one of my tables fails to drop every second time. This would indicate to me that ...

nHibernate Mapping Issue - Cannot Delete members of a collection

Ok. So the situation is: Parent Class which has an IDictionary of Child Classes. I wish these child classes to be deleted when the parent class is. This works fine. I also wish to be able to delete members of the child class individually, and this does NOT work. So my Question is; Why can I not delete these child members? The error ...

(Fluent) NHibernate - Mapping Varchar to Int32

We work with legacy database which are saving integer values to the varchar column. We need to map this column to Int32 property and it works well if data in database column are numeric or NULL. But we have problems if column contains empty string instead of null - nhibernate throws error that it cannot convert it to integer. Is it p...

Is it possible to do Standard Deviation in NHibernate?

Is it possible to calculate Standard Deviation with NHibernate? I'm using the Microsoft SQL Server 2005 Dialect. I can't find any examples of this anywhere. Please help. thanks! ...

NHibernate requires events to be virtual?

I'm attempting to map an entity hierarchy using NHibernate almost all of which have events. When attempting to build a session factory however, I get error messages similar to the following: Core.Domain.Entities.Delivery: method remove_Scheduled should be virtual Delivery is an entity in my domain model with an event called Sched...

How to map a self-reference in NHibernate

Hello, I have a very special NHibernate mapping case. The class has a reference to itself. public class MyClass { public Guid Id { get; set; } public MyClass SelfReference { get; set; } } The data base table has a foreign key field on the primary key of the same table. And event worse, this self reference can be null. Is that p...

Mapping hbm.xml

I have a one-to-many relationship but I'd like to get only one instance to have a one-to-one relationship. I have a class vehicles that may have several owners throughout their life. I only want to map the class to obtain the assets. Is there some way to do this? The problem is in the hbm.xml file. One vehicle may have several owners t...

Fetch child without primary key NHibernate

I am trying to get a collection of objects into a parent object through mapping. I have a parent object "ScoreCard" whose primary key is a guid (Id) and a child "Score" object whose primary key is a guid (Id). I want to select the child objects for the parent based on two fields that both objects have but I can't get it to work, here's ...

Fluent NHibernate HasMany not updating the FK

I'm using latest Fluent NHibernate lib (0.1.0.452) and I have a problem with saving child entitites. I think this is rather common scenario... I've got a parent with mapping: HasMany<Packet>(x => x.Packets) .Cascade.All() .KeyColumnNames.Add("OrderId"); and a simple Packet class that (in a domain model and FNH...

Getting NHibernate.Mappings.Attributes to work Options

I'm using v2.1 of NHibernate.dll and NHibernate.Mappings.Attributes v2.1 in a project. When I run the code further below, I get the following exception, and will be grateful for any pointers. On the same project, if I remove the attributes and use xml mapping files, it works fine. NHibernate.MappingException was unhandled Message="C...

In NHibernate how would I map an object to only retrieve it's children but ignore them when creating or updating?

How would one map this object to only retrieve the collection below and ignore it totally when creating or updating the object to the db? <bag name="children" table="tb_parent_child" lazy="false"> <key column="parentID"/> <one-to-many class="Child"/> </bag> thanks ...

Fluent Nhibernate composed entity, specify foreign key

I have a Fluent Nhibernate map like : public class UserMap : ClassMap<PortalUser> { public UserMap() { WithTable("aspnet_Users"); Id(x => x.Id, "UserId") .GeneratedBy.Guid(); Map(x => x.Name, "UserName"); Map(x => x.Login, "LoweredUserName"); WithTable("LdapUsers", m => m.Map(...

Fluent nhibernate table-per-hierarchy mapping

Hi All, I have a simple scenario where I have an entity Action (this is a workflow style application) that has a DueDate calculated property. Now id like to introduce a SlidingAction, whose only difference (at this stage) is to override the DueDate calculation, as such has none of its own mapping. Im having difficulty mapping this sce...