Questions tagged [fluent-nhibernate-mapping]

Fluent, XML-less, compile safe, automated, convention-based mappings for NHibernate

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.

Resources

626 questions
5
votes
2 answers

Fluent NHibernate many-to-many relationship on existing database

I am mapping an existing database using Fluent NHibernate and have encountered a problem when trying to populate many-to-many collections. The database itself is not set up correctly using foreign keys, here is a simplified example of the problem…
5
votes
1 answer

Setting up one to many relationship with Fluent Nhibernate

I'm having a bit of an argument with my co-worker that I can't seem to find an answer to yet this is very basic stuff. Establishing one-to-many relationship in Fluent Nhibernate entity. Let's take Roles and users for example. A role can be assigned…
InspiredBy
  • 4,271
  • 6
  • 40
  • 67
5
votes
2 answers

NHibernate fluent HasMany mapping inserts NULL Foreign key

I have an entity Company that has many Orders. I mapped these as following to each other: Company HasMany(x => x.Orders).KeyColumn("CompanyID").Cascade.All().Inverse(); Order References(x => x.Company).Column("CompanyID") However when i create a…
scratchyback
  • 127
  • 1
  • 7
5
votes
1 answer

Fluent NHibernate one-to-many relationship setting foreign key to null

I have a simple Fluent NHibernate model with two related classes: public class Applicant { public Applicant() { Tags = new List(); } public virtual int Id { get; set; } //other fields…
5
votes
3 answers

Fluent NHibernate - IndexOutOfRange

I've read all the posts and know that IndexOutOfRange usually happens because a column is being referenced twice. But I don't see how that's happening based on my mappings. With SHOW_SQL true in the config, I see an Insert into the Events table and…
4
votes
2 answers

FluentNHibernate: Getting Column & Table Names After Mapping Conventions Are Applied

I am wondering if it is possible to find the run-time column name for a class/component that has been mapped with FluentNHibernate after all conventions have been applied. For example, given the simple model: public class Address{ public…
Brian Chavez
  • 8,048
  • 5
  • 54
  • 47
4
votes
1 answer

Fluent NHibernate trying to map subclass of subclass using table-per-subclass

I am building an application with heavy inheritance and have a part where there exists classes, A, B and C with: class A class B : A class C : B I implemented subclass mapping as a table-per-subclass style for class B as follows: class BMap :…
4
votes
1 answer

NHibernate 3.2 - Do all properties now require a "set" method?

We recently upgraded our Automapped FNH / NH project to NH 3.2, and are running into a lot of problems. We have a lot of properties in our object model that only have a "getter", e.g. public virtual float Polydispersity { get {…
4
votes
1 answer

NHibernate exception: could not initialize a collection, Invalid column name. Fluent mapping. Maybe a many-to-one issue?

I am puzzled and frustrated by an exception I'm getting via NHibernate. I apologize for the length of this post, but I've tried to include an appropriate level of detail to explain the issue well enough to get some help! Here's the facts: I have a…
4
votes
3 answers

NHibernate joining two table into one entity with a composite key

I have the following data structure : +---------+ |Resume | +---------+ |Id (PK) | |IsActive | |... | |.. | |. | +---------+ +--------------------+ |Resume_Translation | +--------------------+ |ResumeId (PK, FK) | |Language…
4
votes
1 answer

Fluent nHibernate Join

I have an entity that maps to a table called Rule. The table for this entity has an FK to another Table called Category. I'm trying to figure out how to pull in a property from Category in my Rule entity. I'm pretty sure I want to use a join in…
4
votes
1 answer

NHibernate: Require inner join instead of left join for References

How can I change the default join type to be an inner join instead of a left outer join for mappings when I use References? For Example: public class SomeClassMap : ClassMap { public SomeClassMap() { Id(x => Id); …
Joe
  • 1,043
  • 2
  • 12
  • 21
4
votes
1 answer

NHibernate ternary association with multiple values - how to map in a nice way

I've asked a similar question, but I've given up on the idea I had there to solve this problem so I would like some help solving this in a neat way instead. I've got tables Image - (Id, Name, RelativeFilePath) ImageFilter - (Id, Type) ImageContext -…
Max
  • 4,345
  • 8
  • 38
  • 64
4
votes
2 answers

Fluent NHibernate mapping for DateTime with default value

I know that there are many threads about this and I have read most of them. However for me a couple of things remain unclear and still do not work. If I have on my database schema a field of type DateTime and I like to assign it a default value I…
4
votes
2 answers

Fluent NHibernate Foreign Key / Cascading

The problem occurs with the creation of cascading foreign keys using the following Models, where only one Model (UserAddition) knows the other (User) and there is no possibility to add a UserAddition property to the User class: class User { …
1 2
3
41 42