nhibernate

Fluent NHibernate and Schema update/execute - indexes on foreign keys

Is there any way to specify that a foreign key should also be indexed using fluent nhibernate? MS Sql Server does not by default index foreign keys, and I would like the schema generated by the nhibernate schema generation/update tools to create these. When I just use the HasMany or HasManyToMany methods, no such indexes are created. Is ...

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...

Refine: Castle ActiveRecord SessionScope implementation for WCF with PerSession InstanceContext

Hi Guys to facilitate lazy loading on our WCF Services that use AR I created a "Session Scope PerRequest" solution for WCF. [edit] Ok so I put the question on the end :) so bear with me and start reading at the end. :) [/edit] If you want to use ActiveRecord in a website or webservice you have to tell it via the configuration it is run...

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...

NHibernate criteria query question

I have 3 related objects (Entry, GamePlay, Prize) and I'm trying to find the best way to query them for what I need using NHibernate. When a request comes in, I need to query the Entries table for a matching entry and, if found, get a) the latest game play along with the first game play that has a prize attached. Prize is a child of Game...

Determine field by formula on Insert in NHibernate

Hello, I am using NHibernate 2.1. I am inserting records into a table successfully, but I have a SortOrder column that needs to be calculated on insert. The formula will roughly be: SortOrder = (SELECT (MAX(SortOrder) + 1) FROM MyTable WHERE CategoryID = @CategoryID) How can I accomplish this in NHibernate on inserts? Normally I use...

NHibernate: How to use "IN" with CreateCriteria?

I have a parent-child table relationship: Elements -(1 to n)-> ContentBlocks. Each ContentBlock row has: unique Id (Id), ElementId, Version, and then some less relevant fields. I'm trying to get all Content rows that have the highest Version number (and Id) on them. I have this line of SQL that gives me what I want: SELECT * FROM Co...

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 ...

Lazy load nhibernate one-to-one

Hi I have a true one to one mapping. But I would like to use lazy loading(load on demand). I have Class Person with a association with Class Address. The mapping looks like this.. PERSON <one-to-one name="address" class="Person" cascade="all-delete-orphan" access="field"> ADDRESS <class name="Address" table="Address" lazy="true"> ...

Repository + NHibernate + DTO

I have an application with a repository layer (and a nhibernate implementation), service (bussiness) layer, and an asp.net mvc in the web layer. Because I also need to create a small silverlight application I will create several wcf services. This calls to use DTO's, but I don't know how & where to create them. I've seen some links (li...

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...

NHibernate: returning a strongly typed list having applied an aggregate function

I'd like to have nHibernate return a strongly typed list from a CreateQuery invocation using HQL. We'd like a strongly typed list of "MyType" returned, but we'd like to apply an aggregate function to the resultset before it's returned. Unfortunately, as I understand it, adding the aggregate field means nHibernate is unable to match the...

Handling collection properties in a class and NHibernate entities

I was wondering what is the recommended way to expose a collection within a class and if it is any different from the way of doing that same thing when working with NHibernate entities. Let me explain... I never had a specific problem with my classes exposing collection properties like: IList<SomeObjType> MyProperty { get; set; } Hav...

NHibernate Polymorphic Query on a Collection

I'm trying to write a query in NHibernate. I don't really care if I use the Criteria API or HQL, I just can't figure out how to write the query. Here's my model: public class LogEntry { public DateTime TimeCreated { get; set; } } public class Note : LogEntry { public string Content { get; set; } } public class Workflow { public IList<...

NHibernate calling PostgresSQL's SELECT DISTINCT ON ()

Hello, Before asking this question I have googled for some time, but could not find any relevant information on this topic. My problem is simple: I have NHibernate criteria and projection and I'm trying to set DISTINCT ON(column) My code for projection is following: criteria.SetProjection( Projections.ProjectionL...

Nhibernate profiler Question

Hi I'm trying to get session open statistics for nhibernate wtih Nhibernate profiler. We got an issue where a session gets left open on error in transaction mode and gets reused, blowing up when temptables are created. I've got generate statistics on in the config. But I can't see any "Currently open sessions" count and the "Session O...

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....

ASP.NET MVC - Castle ActiveRecord - Show SQL queries

I'm using ASP.NET MVC with Castle ActiveRecord as my persistance layer. I want to know if it's possible to show the SQL queries being executed on my MySQL server. I know it's possible in a Web application using the "show_sql" property in the Castle XML configuration file, but I don't know how to do it using a Web application, since I d...

NHibernate How to Select distinct objects based on specific property using HQL?

How can HQL be used to select specific objects that meet a certain criteria? We've tried the following to generate a list of top ten subscribed RSS feeds (where SubscriptionCount is a derived property): var topTen = UoW.Session.CreateQuery( @"SELECT distinct rss FROM RssFeedSubscription...