nhibernate

Fluent NHibernate one-one mapping through additional table

I have a table A that has a references to a table B through a third table C. C contains the primary key of A and B. For each A there is at most one record in C. When I try to create a mapping for A such that I am referencing B, I use the References function, but it does not allow me to specify that the mapping goes through another table ...

Filter on joins in nHibernate

I’m trying a build an nHibernate criteria expression to perform a search. Given the following data model: An operation may have zero or more sessions. An operation may be of zero of more operation types. I want to search for all sessions based on the following criteria: (Mandatory) Where the operation IsActive flag is true, ...

NHibernate code completion Visual Studio

Hi, I know there is a way to enable code completion for hibernate-mapping files. But I can't remember how I have to do this. Can someone help me out pls? Kind Regards, Sem ...

NHibernate mapping trouble

Hello. I have the following object model: A top-level abstract class Element with many children and descendants. A class Event. Each Element contains a bag of Events. Each Event has a pointer to the parent Element. Up till now - pretty standart one-to-many relationship. But, I want to use table per concrete class strategy. So, t...

Lazy loading not working for many-to-one relationship when mapping to a non-key field using property-ref

I have a legacy database that I am mapping using NHibernate. The objects of concern are an Account and a list of Notification objects. The objects look like: public class Notification { public virtual int Id { get; set; } public virtual DateTime BatchDate { get; set; } /* other properties */ public virtual Account Acco...

Order by collection count using ICriteria & NHibernate

Using the standard NHibernate example of Cats and Kittens, how would I use ICriteria to sort Cats based on Kitten count? For example, I want to do something like: ICriteria crit = Session.CreateCriteria(typeof(Cat)); return crit.Order(Order.Asc("**Kittens.Count**")); Anyone know how to achieve this? ...

Enum tables in Hibernate/NHibernate

We are using NHibernate, and one of the common patterns we have for storing enum-like information is to define separate tables for the enum, and just make a reference to the ID in the main entity/table that uses the enum. A simple example: Message ------- ID (bigint PK) MessageTypeID (bigint FK) Body (varchar) MessageType ----------- ...

SchemaExport, NHibernate and deleting foreign keys

I am building my mapping and then using schema export to update my DB. However, if I delete an association in my mapping, since it's no longer in the mapping, when I run SchemaExport, it will not delete the foreign key for the deleted association. This means that it then fails to drop the table associated with that foreign key. Which fur...

NHibernate mappings when self-join relationships have additional properties

How do you map a class to other instances of the same class when that relationship has properties itself? I have a class called Person which is mapped to a table Person PersonID PersonName PersonAge ---------------------------------- 1 Dave Dee 55 2 Dozy 52 3 Beaky ...

What is the impact of lazy="false" on class element of NHibernate mapping?

I'm working with a legacy system that I'm experimenting with adding NHibernate to. I have class that I need to be mapped to a table, but it has lots of existing methods that are not virtual. I discovered that I can get NHibernate to load the mapping successfully even with the non-virtual methods present if I set the "lazy" attribute on...

Mapping collection of strings with NHibernate

Hi, I have a domain class with a property IList<string> that I want to map to a table with a single data value (i.e. it has an ID, a foreign key ID to the domain entity table, and a varchar data column). I keep getting the error: 'Association references unmapped class: System.String'. How can I map a table to a collection of strings? ...

Nhibernate: Make Many-To-Many Relationship to Map as One-To-One

I have two items A and B, which have a uni directional one-to-one relationship. (A has one B) In the database these are represented by ATable and BTable, and they are linked together by ABTable. (From the database setup it appears there is a many-to-many relationship but there is not, it was done this way for normalization reasons). ...

NHibernate DataTypes - NoYes Boolean

What is the best way to get the reverse behavior of the YesNo Boolean type in NHibernate mapping? I want 'Y' to mean false and 'N' to mean true. Is there a NoYes type? Do you write a custom type? something really easy? This issue of needing to reverse the Boolean exists on at least one field on over 40 tables. Trying to adapt to a leg...

Generate table indexes using Fluent NHibernate

Is it possible to generate table indexes along with the rest of the database schema with Fluent NHibernate? I would like to be able to generate the complete database DDL via an automated build process. ...

nhibernate proxy generator

I am attempting to get nhibernate working in medium-trust. What I found said that I needed to use a proxy generator. I pulled the one from nhibernate's site. When I attempt to use it, I recieve an error that it could not load the assembly 'DynamicProxyGenAssembly2'. Is there something I am missing or is there one that works somewhere...

NHibernate - Reflection or DynamicMethod ?

I have used NHibernbate in few projects and now learned about few more ORMs also. I understand that, NHibernate binds Class to Datalayer dynamically during runtime using the mapping file. My Question is , how this late binding is done ? I mean, which Methodology is used, 'Reflection' or 'DynamicMethod' ? In case, if it uses Reflection,...

NHibernate filters don't work with Session.Get

I'm trying to implement a Soft-deletable repository. Usually this can be easily done with a Delete Event listener. To filter out the deleted entities, I can add a Where attribute to my class mapping. However, I also need to implement two more methods in the repository for this entity: Restore and Purge. Restore will "undelete" entities a...

How do I run an HqlBasedQuery that returns an unmapped list of objects using nHibernate?

I want to run a query against two tables (which happen to be mapped in ActiveRecord). The query returns a result list that cannot be mapped to an ActiveRecord object (as it is custom aggregate information). For instance Dim query_str as string = "Select distinct d.ID, (select count(1) as exp from Sales_Leads where date_created <= :tod...

Enabling Nhibernate filters by default

Is there a way to make sure a filter (<filter-def>) in enabled by default as opposed to having to call session.EnableFilter("filter_name") everytime? ...

Counting subqueries in NHibernate HQL

I need to do something like the following: select d.ID, count(from Lead l where l.DateCreated > DATEADD(day, -30, :todays_date) AND l.DealerId=d.ID), count(from Lead l where l.DateCreated < DATEADD(day, -30, :todays_date) and l.DateCreated >= DATEADD(day, -60, :todays_date)) FROM Dealer d GROUP BY d.ID Ordinarily I could do this: SE...