nhibernate

How to query: Select games in categories A, B and C

I'd like to know how to effectively run a query such as: select game from Game game inner join game.Categories cat where cat.Name in ('A', 'B') This gives me games with categories A or B. But I want games that the the A category and the B category. This is to be used in HQL (NHibernate Query Language), but I'd like also to know how t...

IndexOutOfRangeException Deep in the bowels of NHibernate

I have the following mappings: public class SecurityMap : ClassMap<Security> { public SecurityMap() { Table("Security"); CompositeId().KeyProperty(k => k.Id, "SecurityId").KeyProperty(k => k.EndDate); Map(x => x.LastUpdateUser); References(x => x.Company).Columns("Compa...

Asp.Net MVC + NHibernate + Widget Plugin Architecture

Updated: This is a re-write from my original question (or lack of), the main problem I am having at the moment is that when mapping my Widget domain models to the correct ViewModel I am having to do it like this which is definetly not the right solution... public ProfileWidgetViewModel MapFrom(ProfileWidget input, Account userAccount) ...

Deep copy entity with NHibernate

I am currently starting a new ASP.NET MVC Project at work where we need to generate a project cost estimate. We are using NHibernate, ASP.NET MVC 1.0 and StructureMap. The client wants to be able to fill all the information about the project, the information is in different pages and we need to persist in between each post back. The ...

NHibernate Composition Composite Key problem

I have a class that is composed of 2 composite key objects and they share a column ‘SharedColumn’. This maps fine and the composite classes’s one-to-Many mappings work fine. <class name="PAIR"> <composite-id> <key-many-to-one name="first" class="Class1"> <column name="SharedColumn"/> <column name="Column1" /> ...

How to map count of collection to entity with fluent-nhibernate

With employees and subordinates - I want to load an employee with the count of subordinates in one query. public class Employee { public Name {get;set;} public int NumberOfSubordinates {get;set;} } Resulting SQL should look like : select e.name, (select count(*) from subordinate s where s.employee_id = e.id) NumberOfSubordin...

How to use ASP.NET to connect to a remote Oracle database?

I have Oracle (10g Express Edition) installed on one pc. Visual Studio 2008 SP1 is installed on another pc. I want to run an ASP.NET web app that uses the remote database. The two PCs are connected by a LAN (wired) connection. How can I connect to the database? What will the connection string be? The operating system on both PCs is Win...

LINQ string compare in VB when using NHibernate

Hi Come across an issue when doing a string compare as part of the where section of a linq expression against LINQ for NHibernate. from x in NhibernateObject where x.StringCol = "value" select x When it runs it retrns a runtime error about casting to an integer. I found a nice post about the issue and the solution at http://jason.pe...

NHibernate 2nd level cache provider for NHibernate 2.1.1.4000

I am using s#arp which is built against NHibernate 2.1.1.4000, However I would like to use NHibernate.Caches.SysCache as my second level cache. However the Nhibernate contrib caches are built against NHibernate 2.1.2.4000 which obviously gives me a problem. Can anyone point me to a URL that I can download NHibernate.Caches.SysCache.dll ...

Is it possible to configure NHibernate at runtime setting the loading-technique (eager/lazy) for a collection

Ya is this possible :) ? ...

Fluent NHibernate Solution Structure - How to reference DLL's once in back end of Web App / Console App

I'm organizing a VisualStudio 2008 solution using Fluent NHibernate and I would like to keep all the NHibernate dll dependencies buried in a "Back End" class library and let the front end Web app or Console app be ignorant of NHibernate. My Solution structure is as follows: BackEnd -- Class Library -- Business logic and Data Reposito...

Should you use outer join fetching with NHibernate and Sql Server 2008?

On outer join fetching, the Nhibernate documentation says: If your database supports ANSI or Oracle style outer joins, outer join fetching might increase performance by limiting the number of round trips to and from the database (at the cost of possibly more work performed by the database itself). Outer join fetching al...

Unit testing NHibernate w/ SQLite and DateTimeOffset mappings

Porting over an application to use NHibernate from a different ORM. I've started to put in place the ability to run our unit tests against an in memory SQLite database. This works on the first few batches of tests, but I just hit a snag. Our app would in the real world be talking to a SQL 2008 server, and as such, several models cur...

Strange problem with LINQ to NHibernate and string comparison

I'm using LINQ to NHibernate and encountered a strange problem while comparing strings. Following code works fine but when I un-comment: //MyCompareFunc(dl.DamageNumber, damageNumberSearch) && and comment: dl.DamageNumber.Contains(damageNumberSearch) && then it breaks down and seems that MyCompareFunc() always return true while dl.Damage...

NHibernate mapping problem

Hello, I have a table like: CREATE TABLE [dbo].[MOVIES_HISTORY]( [DATE] [datetime] NOT NULL, [COUNT] [int] NOT NULL CONSTRAINT [DF_MOVIES_HISTORY_COUNT] DEFAULT ((0)), CONSTRAINT [PK_MOVIES_HISTORY] PRIMARY KEY CLUSTERED ( [DATE] ASC )WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY] ) ON [PRIMARY] Class: using System;...

How to check if the key is an unsaved value in NHibernate

I am creating a model binder to use with asp.net mvc. This is what I got so far: public class ModelBinder : DefaultModelBinder { protected override object CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Type modelType) { PersistentClass mapping = DataAccess.Configuration.GetClassMappi...

fluent nhibernate manytomany mapping

Hi guys, I am trying to map these entities Messages table fields are Id generated Id,SentFrom int, sentTo int where Sentfrom and sentTo are linked to the users table I also have a linker table MessageUser table with userId and MessageId CREATE TABLE [dbo].[MessageUser]( [MessageId] [int] NOT NULL, [UserId] [int] NOT NULL, CONSTRA...

How to write Tests for Data Access Layer in .Net?

Is there a framework to write unit test for Data Access layer? There are several issues in this. 1. How to populate your database? 2. How do we make sure that one test is not modifying values in db that can fail another test? Is there a good framework available which can take care of above issues? Update: I came across nDBUnit which ...

Group By with Count using NHibernate

Given the following tables: Resources: ID int, Name varchar(100), Address varchar(500), City varchar(100), etc. ResourceViews: Id int, resourceId int, userId int, viewDate DateTime every time a resource is looked at, an entry is added to the ResourceView table for that user. Here are the corresponding classes: public class Resource {...

Fluent NHibernate issue with nvarchar(max) and sql express 2005

I have recently updated from NH2.1 to the latest trunk build. I also upgraded to the latest source code of Fluent NHibernate. A new issue has been introduced which manifests as the following exception : System.Data.SqlClient.SqlException: The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. P...