fluent-nhibernate

Mapping person and employee in Fluent NHibernate

How can I map following queries using Fluent NHibernate (entity, mapping class etc..), the employee ids are stored in identifier tables. Person table contains employee information and non-employee information. SELECT p.Id, p.FirstName, p.LastName FROM Person p UNION ALL SELECT e.Id, e.FirstName, e.LastName FROM Employee e ...

How to convert Castle Activerecord to pure NHibernate or Fluent NHibernate?

I'm going to refactor a growing project from using Castle Activerecord to pure NHibernate or Fluent NHibernate with Service/Repository pattern and POCO. What would be an easiest way to obtain hbm xml from existing Castle Activerecord model? Another question, is it possible to convert hbm to Fluent NH and vice versa? ...

Export all sql generated by NHibernate to a text file.

I have a console app that exports my entity models to my sql db and I am able to export that schema to an .sql file without issue. However, my DBA's want .sql files for all the initial data that should be populated in the db as well. My console app uses NHibernate to save a bunch of objects to the database right after it creates the data...

Fluent Nhibernate No Persistor for Class Name

I am getting this error even though all my mappings are pretty simple and correct. I get this error only on select classes. Can someone help? ...

Fluent NHibernate mixed mapping properties

Hi! I'm trying to use fluent nhibernate to auto map most properties of a class, and then manually map 1 or 2 properties of that same class (without having to manually map all the other variables in the class map). I have a class with a couple of dozen properties, but one of those properties is a string which needs to be a long length. ...

What is the use case for Access.BackingField in Fluent NHibernate?

The documentation for Access.BackingField() indicates that this: Sets the access-strategy to use the backing-field of an auto-property. I understand that auto-properties get compiled with backing fields, but if the property is by definition a vanilla getter/setter, what advantage is garnered by going to the backing field directly v...

Filters not being applied for many-to-one reference

I have a bit of an odd scenario where I have a table that references a view that contains rows which are user-specific. The view has a unique row ID, but it is never used to reference the item. Instead a unique value is derived from a combination of a client ID, user ID, and an object key. public BarMap() { Table(Datab...

How do I automap a component collection in Fluent NHibernate?

I have a TrackLog that contains a collection of GPS points as a TrackPoint object: public class TrackPoint { public virtual int Id { get; set; } public virtual List<TrackPoint> TrackPoints { get;set; } } public class TrackLog { public virtual double Latitude { get; set; } public virtual double Longitude { get; set; } ...

Example of a simple ASP.NET MVC + NHibernate + Fluent with proper session handling?

I'm new to all of these technologies. I would like to see a simple (not over the top) example of how you would set up a project with these technologies. The most important being the proper NHibernate session handling (using HttpContext). Or we can build off of what I already have. I've seen several examples of one piece or another but n...

Transactions in NHibernate - UPDATE then INSERT. What am I doing wrong?

In this sample console app I want to update a row in a table, and then insert another row in the same table. The table is like this CREATE TABLE [dbo].[Basket2]( [Id] [int] IDENTITY(1,1) NOT NULL, [UserId] [int] NULL ) ON [PRIMARY] CREATE UNIQUE NONCLUSTERED INDEX [IX_Basket] ON [dbo].[Basket2] ( [UserId] ASC ) So basi...

NHibernate many-to-many and SELECT N+1 problem

I have 4 database tables (Channel, User, Message, User2Channel) and according entity classes: class **Channel** { int ChannelId {get;set;} int ISet<User> UsersToChannel {get;set;} ... } class **Message** { int MessageId {get;set;} Channel Channel {get;set;} User User {get;set;} ... } class **User**{ int UserId {get;set;} ISet<...

Fluent NHibernate Many-To-Many with Additional Data

We process specialty ads for companies. These companies have a number of stores that have unique ads but share some ads. These ads that are shared across stores may appear on a different pages for each store. So I have a database like this: Specialty SpecialtyAd: SpecialtyId, AdId, AdNumber(Think of this as a page number.) Ad (Really a ...

Fluent NHibnerate Domain mapping issue

My Domain: public class Person { public Person() { } public virtual int PersonId { get; set; } public virtual string Title { get; set; } public virtual string FirstName { get; set; } public virtual IList<Address> Addresses { get; set; } } public class Address { public Address() {} public virtual int Addre...

IgnoreProperty and Reveal.Member on Fluent NHibernate 1.1.0.685 on component type

I'm trying to ignore the property which is a ReadOnlyCollection and map the private property. I'm getting the following error: Could not find a setter for property 'MyCollection' in class 'Project.Core.MyClass' This is the automapper for that class which is a component. mapping.IgnoreProperty(x => x.MyCollection); mapping.HasMany<Col...

How do I make an IgnoreProperty convention in fluent nhibernate?

public class MyObjectMap : IAutoMappingOverride { public void Override(AutoMapping mapping) { mapping.IgnoreProperty(x => x.InterfaceProperty); } } I am currently doing this in every map... how can I make this into a convention? I am adding conventions like so: private Action<IConventionF...

Fluent NHibernate : How to map a 'Foreign Key' column in the mapping class

I'm starting to develop with Fluent NHiberate, and I was wondering how I create a defined 'Foreign Key' relationship in my Mapping class. Here's my class. These classes are a one-to-one with associated tables. public class Song { public virtual int SongID{ get; private set; } //Primary Key public virtual int SongArtistID { get...

Implementing Nhibernate one to many mapping

Hi, I have a class School and another class Teachers. now every school can contain m Teachers and one Teacher may be part of more than one school. But in the Teachers class I dont want a property that tells me which Schools a teacher is part of. Thus, public class School { public virtual int Id {get;set;} public virtual string Name {g...

Cannot set a default Nhibernate isolation level (eg via mapping)

This has been a problem that has existed on 3 projects for me. I have tried the following: <property name="connection.isolation">ReadCommitted</property> Set in hibernate.cfg.xml Using fluent nhiberate: MsSqlConfiguration.MsSql2008.IsolationLevel(IsolationLevel.ReadCommitted); Set in global.asax.cs I have always been forced to s...

Multiple ClassMaps classes in NHibernate

Is this possible in fluent nhibernate having multiple mappings for one table? Lets suppose i have a Users table. Once i want it to be apped exactly like in file UserMap1.cs, and some times I would rather prefer mapping from UserMap2.cs. I don't need to switch configurations while app is running. I just have to choose a proper one at th...

NHibernate with Inversion of Control

This is just something I've been thinking about and was wondering if it exists, or even if its beneficial at all. I'm doing inversion of control and dependency injection using Unity. I'm also doing ORM with fluent nHibernate. I was wondering if there was a way to either configure nHibernate to take interfaces as its type parameters an...