nhibernate

Disctinct from the table

ICriteria crit = session.CreateCriteria(); foreach (ICriteriaItem<object> param in filters) { crit.Add(Expression.Eq(param.PropertyName, param.FilterValue)); } crit.SetProjection(Projections.Distinct(Projections.ProjectionList())); -- disctinct not wo...

NHibernate Session per Call in WCF - How to Rollback

I've implemented some components to use WCF with both an IoC Container (StructureMap) and the Session per Call pattern. The NHibernate stuff is most taken from here: http://realfiction.net/Content/Entry/133. It seems to be OK, but I want to open a transaction with each call and commit at the end, rather than just Flush() which how it...

Nhibernate Criteria Query with Join

I am looking to do the following using an NHibernate Criteria Query I have "Product"s which has 0 to Many "Media"s A product can be associated with 1 to Many ProductCategories These use a table in the middled to create the join ProductCategories Id Title ProductsProductCategories ProductCategoryId ProductId Produ...

Delete only reference to child object

I'm running in to a bit of a problem where any attempt to delete just the reference to a child also deletes the child record. My schema looks like this Person Organisation OrganisationContacts : Person OrgId PersonId Role When removing an Organisation i want to only delete the record in OrgnaisationContacts, but not touch the Person...

NHibernate Linq queries not returning data saved in the same transaction

Hi, I have a situation where I am using NHibernate in a WCF service and using a TransactionScope for the transaction management. NHibernate enlists in the ambient transaction fine, but, any changes I make and save inside the transaction, are not visible to any queries I make while still in that transaction. So if I add an entity and ses...

nHibernate criteria - how do I implement 'having count'

I have the following table structure and I want a turn the query into a NH criteria but I'm not sure how to incorporate the correct 'Projection', does anyone know how? And the query I want to turn into a Criteria: select ComponentId from Table_1 where [Name] = 'Contact' or [Name] = 'CurrencyPair' group by ComponentId having count(Ver...

nHibernate Self Join Mapping

Hi Guys, This is probably incredibly simple, but I just cant see the wood for the trees at the moment. For brevity, I would like to model a word object, that has related words to it (synonyms), In doing so I could have the following mappings: <class name="Word" table="bs_word"> <id name="Id" column="WordId" type="Int32" unsaved-value=...

Mapping a localized string with NHibernate

Most of our lookup tables have corresponding localization tables. Something like this for example: create table GENDERS ( GENDER_CODE char, DESCRIPTION varchar ) -- Localization table: create table LC_GENDERS ( LOCALE varchar, GENDER_CODE char, DESCRIPTION varchar ) In this example the default (en-US) values are ...

how to call sql string from nhibernate

i have the following method, at the moment it's return the whole sql string. How would i execute the following. using (ITransaction transaction = session.BeginTransaction()) { string sql = string.Format( @"DECLARE @Cost money SET...

Is it a good idea to create an interface for each domain objects?

I was just looking into the source code of an existing project which uses nHibernate and found that there are interfaces created for each entity classes. E.g ICustomer for Customer class. I was just wondering what can be the advantage of this pattern as ICustomer contains mainly the properties and very few methods. ...

NHibernate update using composite key

Hi, I have a table defnition as given below: License ClientId Type Total Used ClientId and Type together uniquely identifies a row. I have a mapping file as given below: <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true"> <class name="Acumen.AAM.Domain.Model.License, Acumen.AAM.Domain" lazy="false" table...

nHibernate adding criteria

crit.Add(Expression.IsNotNull(sortField)); i want to add the condition where sortfield is not null or empty how do i do that ...

Prevent lazy loading in nHibernate

Hi, I'm storing some blobs in my database, so I have a Document table and a DocumentContent table. Document contains a filename, description etc and has a DocumentContent property. I have a Silverlight client, so I don't want to load up and send the DocumentContent to the client unless I explicity ask for it, but I'm having trouble do...

NHibernate: inserting additional calculated column

What would be your approach with NHibernate to do the following: When Comment is inserted into DB, and its property Text is inserted into column Text (due to a mapping), insert into column TextHash a hash of this property value. It seems trivial if I map TextHash, but how should I do this without mapping it? I do not need it in the doma...

Is there anything wrong with this many-to-many Fluent Nhibernate mapping?

i have this: <set name="Identities" table="tIdentityGroups" inverse="true" batch-size="10" cascade="none"> <cache usage="read-write" /> <key column="GroupID" /> <many-to-many class="Identity" column="IdentityId" /> </set> and have translated it to this: HasManyToMany<Identity>(x => x.Identities) .Tab...

NHibernate, each property is filled with a different select statement

I'm retrieving a list of nhibernate entites which have relationships to other tables/entities. I've noticed instead of NHibernate performing JOINS and populating the properties, it retrieves the entity and then calls a select for each property. For example if a user can have many roles and I retrieve a user from the DB, Nhibernate retrie...

Castle ActiveRecord / NHibernate Linq Querys with ValueTypes

Given the following code for our Active Record Entites and ValueTypes Linq is not working for us. [ActiveRecord("Person")] public class PersonEntity : ActiveRecordLinqBase<PersonEntity> { string _name; [Property("Name", Length = 20, ColumnType = "string", Access = PropertyAccess.FieldCamelcaseUnderscore)] public Name Name ...

Are there ways to improve NHibernate's performance regarding entity instantiation?

Hi folks, while profiling NHibernate with NHProf I noticed that a lot of time is spend for entity building or at least spend outside the query duration (database roundtrip). The project I'm currently working on prefetches some static data (which goes into the 2nd level cache) at application start. There are about 3000 rows in the result...

nHibernate - eager fetching a list with child lists already populated

I have some objects: Public Class Person() { public int Id {get;set;} public IList<Account> Accounts {get;set;} public string Email {get; set;} } public class Account(){ public int Id {get;set;} public IList<AccountPayment> Payments {get;set;} public IList<Venue> Venues {get;set;} } public class AccountPayment(...

Merge Function In Entity FrameWork?

when i use NHibernate i can find Merg function in session which do that : * if there is a persistent instance with the same identifier currently associated with the session, copy the state of the given object onto the persistent instance * if there is no persistent instance currently associated with the session, try to load it from the ...