Questions tagged [fluent-nhibernate]

Fluent NHibernate lets you write NHibernate mappings in strongly typed C# code. This allows for easy refactoring, improved readability and more concise code.

Fluent NHibernate offers an alternative to NHibernate's standard XML mapping files. Rather than writing XML documents (.hbm.xml files), Fluent NHibernate lets you write mappings in strongly typed C# code. This allows for easy refactoring, improved readability and more concise code.

Installation Fluent NHibernate can most easily be installed through its NuGet package.

Install-Package FluentNHibernate

Resources

5486 questions
21
votes
1 answer

Fluent nHibernate: Use the same mapping files for tables with the same structure in different schemas

This is my mapping class: class MyTableMap : ClassMap { public MyTableMap() { Schema("mySchema"); Id(x => x.id); Map(x => x.SomeString); } } This works fine for the Table…
Gener4tor
  • 414
  • 3
  • 12
  • 40
21
votes
6 answers

Enum to integer mapping causing updates on every flush

I am trying to map an enum property (instance of System.DayOfWeek) in my model to an integer database field. Other enum properties in the model should be mapped to strings, so I don't wish to define a convention. I understand that this should be…
Ian Nelson
  • 57,123
  • 20
  • 76
  • 103
21
votes
2 answers

Fluent NHibernate: How to map an entire class as ReadOnly?

I have a few classes that read from very delicate tables, which is why I want them to be used by NHibernate as "ReadOnly". Establishing .ReadOnly() on each field map is really sloppy, and I'm not sure I trust it. How do I setup a class to be…
rebelliard
  • 9,592
  • 6
  • 47
  • 80
21
votes
3 answers

NHibernate -failed to lazily initialize a collection of role

I have the following seemingly simple scenario, however I'm still pretty new to NHibernate. When trying to load the following model for an Edit action on my Controller: Controller's Edit Action: public ActionResult Edit(Guid id) { return…
jamesaharvey
  • 14,023
  • 15
  • 52
  • 63
21
votes
1 answer

Fluent NHibernate primary key constraint naming conventions

Is there any way to create a naming convention for my primary key constraints in Fluent NHibernate? I know you can name foreign key constraints, but it does not appear possible to name the primary key constraint.
Brett
  • 2,101
  • 2
  • 16
  • 20
20
votes
3 answers

fluent nhibernate - many-to-many relationship mapping on same entity

I am having a problem trying to map out a many-to-many relationship , where both sides of the relationship reference the same entity. I am using Fluent NHibernate and NH3.1. Basically, the scenario is this - I have a category, which can have…
20
votes
1 answer

Inserting a collection of entities in bulk using Fluent NHibernate

I'm trying to insert a large collection of objects into a table using fluent NHibernate, using a call to save or update passing each entity from the collection in a foreach loop. I had been setting the batch size to the size of the collection,…
Ian Cotterill
  • 1,667
  • 4
  • 18
  • 28
19
votes
1 answer

Fluent NHibernate FluentMappings.AddFromAssemblyOf<> Issue

A coworker and I were recently doing the backend for a small application using Fluent NHibernate. We wrote our entities, mapping files, persistence manager, but for some reason we couldn't export the database schema to anything. Through the debugger…
Cody
  • 3,734
  • 2
  • 24
  • 29
19
votes
8 answers

To Multi-Tenant, or Not To Multi-tenant

I have a difficult database design decision to make regarding multi-tenancy for the growing number of branches of my client's web-based CRM, which I actively maintain. I made the decision early on to use separate applications with separate databases…
Petrus Theron
  • 27,855
  • 36
  • 153
  • 287
19
votes
8 answers

NHibernate: Using Fluent Nhibernate to save child objects

In my system, I have two entities - ShoppingCart and ShoppingCartItem. Fairly generic use-case. However, when I save my ShoppingCart, none of the items are being saved to the DB. Within my object, I create a new ShoppingCart object. ShoppingCart…
Ben Hall
  • 1,927
  • 5
  • 25
  • 39
19
votes
2 answers

Fluent NHibernate cascade delete not working

I've got a simple phone directory app using Fluent NHibernate 1.1. In the app, a "Person" object has many "PhoneNumber" objects. I'm trying to delete a Person and I want to cascade deletes to PhoneNumbers. I set a convention of DefaultCascade.All()…
Matt Winckler
  • 2,223
  • 2
  • 23
  • 27
19
votes
2 answers

Composite Key/Id Mapping with NHibernate

I have the following tables in my database: Announcements: - AnnouncementID (PK) - Title AnouncementsRead (composite PK on AnnouncementID and UserID): - AnnouncementID (PK) - UserID (PK) - DateRead Users: - UserID (PK) - UserName Usually I'd map…
19
votes
2 answers

Fluent NHibernate "Could not resolve property"

I have read a lot of the questions about that same error but none since to match my exact problem. I'm trying to access the property of an object, itself part of a root object, using Fluent NHibernate. Some answers say I need to use projections,…
Astaar
  • 5,858
  • 8
  • 40
  • 57
19
votes
2 answers

Fluent NHibernate Map Enum as Lookup Table

I have the following (simplified) public enum Level { Bronze, Silver, Gold } public class Member { public virtual Level MembershipLevel { get; set; } } public class MemberMap : ClassMap { Map(x =>…
Jaimal Chohan
  • 8,530
  • 6
  • 43
  • 64
19
votes
2 answers

Issuewith NHibernate, Fluent NHibernate and Iesi.Collection. What would you try next?

I'm extremely new to NHibernate so I apologize if I missing something trivial here. I am currently working through a book titled "NHibernate 3 Beginners Guide" from packtpub. I have mostly been following the directions in the book. When I say mostly…
Frito
  • 1,423
  • 1
  • 15
  • 27