fluent-nhibernate

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

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

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

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

Fluent NHibernate - What's the best way to have two one-to-many mappings to the same entity

Hello, I need a little help to map the following structure using Fluent NHibernate. The logic behind my classes is to have a question that contains a list of choices and one answer. Each answer contains a sub-list of the choices contained by the question. I hope the code below is more clear I've minimized the code for each class to...

Fluent Nibernate putting a where clause in the mapping

Hi, I've got two objects a parent and a child list. In my fluent nhibernate mapping for the parent I want to load the list of the children. However I want this to be conditional, a column in the child table is called "IsDeleted" and I only want to return the children where "IsDeleted" is false. Is it possible to set up a mapping to d...

Fluent NHibernate CheckProperty and Dates

I setup a NUnit test as such: new PersistenceSpecification<MyTable>(_session) .CheckProperty(c => c.ActionDate, DateTime.Now); When I run the test via NUnit I get the following error: SomeNamespace.MapTest: System.ApplicationException : Expected '2/23/2010 11:08:38 AM' but got '2/23/2010 11:08:38 AM' for Property 'ActionDate' ...

How to add a read-only collection property in (Fluent) NHibernate?

I want to control my domain's interaction with a collection, so I thought I'd make the collection protected and provide a read-only wrapper around it so that the contents are visible, but I can ensure that items are not added directly to the collection. So I have the following code: public class MyClass { public virtual ICollectio...

Fluent Nhibernate, Composite Keys and could not resolve property: error message

Hi, I've got a simple object with three properties. This links to a table with three columns, with two of the columns being primary keys (one int the other a datetime). Whenever I try and query nhibernate I get the following error message: could not resolve property: invdate of:Models.Invoice Have I missed something simple in se...

Fluent NHibernate Auto Mapping table to fully qualified name

I'm using Fluent NHibernate auto mapping. I need to access more than one database on the same server is it ok to override the table name with the fully qualified name. For example my connection string is configured to Db1 but I need to access table Company on Db2 on the same server. I tested the code below and it seems to work I'm just w...

Map table inheritance as a one-to-one relationship with NHibernate

Hi! I have a database that has a one-to-one relationship modeled between a Person and a Address (that uses person id). However, I cannot find a way to make the map using NHibernate. My table structure is the following: PersonTable PersonId PersonName PersonAge AddressTable PersonId CountryName StreetName StateName And I would l...

NHibernate - When FlushMode is given as Never and if I close the session by session.Close(), will the changes be sent to server?

If I have the FlushMode as Never and if I do a session.Close() will the changes be persisted to the database? Or do we have to explicitly say session.Flush() before session.Close()? Thanks ...

DateTime incorrect when added to SQLite DB through (Fluent)NHibernate

I have a component that i want to store to an SQLite database. public class Comp : Entity { public virtual DateTime TimeStamp { get; set; } public virtual String Name { get; set; } } public class CompMap : ClassMap<Comp> { public CompMap() { Id(x => x.Id); Map(x => x.TimeStamp); Map(x => x.Name);...

Override for fluent NHibernate for long text strings nvarchar(MAX) not nvarchar(255)

When ever you set a string value in fluent NHibernate it alwasy sets the DB vales to Nvarchar(255), I need to store quite a lot of long string which are based on user inputs and 255 is impractical. Just to add this is an issue with the automapper as I am using fluent NHibernate to build the database. ...

How do I use the IHasManyConvention Fluent NHibernate convention to set the PropertyRef on a HasMany mapping?

Currently I'm using Fluent NHibernate to generate my database schema, but I want the entities in a HasMany relationship to point to a different column for the reference. IE, this is what NHibernate will generate in the creation DDL: alter table `Pony` add index (Stable_ID), add constraint Ponies_Stable foreign key (Stable_Id) references...

Fluent NHibernate: setting string to be sql type of "varchar" instead of "nvarchar"

I have the following mapping: public class LogEntryMap { public LogEntryMap() { Map.Id(x => x.Id).GeneratedBy.Identity(); Map(x => x.Context).CustomSqlType("varchar").Length(512); } } However, using SchemaExport to generate the database in SQL Server 2008, the script generated ignores the length so in effec...

Basic Fluent NHibernate program compiles and runs, but nothing is saved to or loaded from database

I am trying a very simple Fluent Nhibernate example: SQL 2005 database with one table, VS2008 console application. The table has one record before the program starts. I am trying to add one record, then display all records from table. Programs successfully compiles and runs without any exceptions, however no records are displayed. HBM m...

How to Avoid Exposing the Domain Layer to the Infrastructure Layer with FluentNHibernate Configuration?

I have my NHibernateUtil class in the infrastructure layer of my application, however I arrive at a problem with this line: ... .Mappings(m => m.FluentMappings.AddFromAssemblyOf<Computer>()); For this to work I have to expose the domain layer to the infrastructure layer. The domain layer also has access to the infrastructure layer due...

How to get Fluent NHibernate working with NHibernate 3.x

How to get Fluent NHibernate working with latest NHibernate 3.x trunk I got the following Exception : Could not load file or assembly 'NHibernate, Version=2.1.2.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4' or one of its dependencies. EDIT : This exception occurs in FluentNhibernate file PersistanceConfiguration publi...

nhibernate cache problem with linq queries

I am seeing some odd behavior from nhibernate caching and cannot understand the reasoning. I am not able to cache queries when doing select operations like query.Select(x=>x).ToList() but can cache when doing: var query = session.Linq<Promoter>(); var p = query.ToList(); Both produce the same sql query and should be doign the sam...