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
3
votes
1 answer

Same entity relationship using FluentNHibernate

I'm trying to create a relationship to the same entity using FluentNHibernate but do not know how. Has anyone succeeded? Can you help me? This is my entity class: public class Menu { public virtual Guid MenuId { get; set; } public virtual…
3
votes
1 answer

Fluent NHibernate automapping composite id with component

I have this complex situation: a database of countries/regions/states/cities which primary key is composed by a code (nvarchar(3)) in a column called "Id" plus all key columns of "ancestors" (regions/states/cities). So the table country has only one…
Hellraiser
  • 579
  • 7
  • 18
3
votes
1 answer

NHibernate (Fluent) Lazy Loading Not Working

I am attempting to use NHibernate to generate a model for a very odd database. The tables themselves have primary keys for show only, all the actual relationships are on unique columns. For example, a product table with a product id primary key and…
3
votes
1 answer

Linq to nHibernate Fetch gives error "A fetch request must be a simple member access expression" when used with a component

I have two classes: public class Reference { public virtual string Id { get; set; } // ... public virtual Stamp Stamp { get; set; } } public class Stamp { public DateTime? Created { get; set; } public User CreatedBy { get; set; } …
3
votes
2 answers

Map foreign key as well as reference in NHibernate without creating extra column

I want to map both the foreign key as a POCO property and the navigation property. IE in the example here , the answer substitutes the foreign key public virtual int SongArtistID { get; set; } I want to keep that key in the mapping. I have tried…
3
votes
1 answer

Fluent nhibernate mapping nested properties "cannot find getter"

Ok, this may be a double-question. I have a class User, which contains a property Location of type UserLocation. At first, I was mapping both the User class and the UserLocation class and storing them both in the db, but that didn't make a lot of…
3
votes
1 answer

Unable to find assembly FluentNHibernate when mapping Component while running Fitnesse test

I have run into a very weird issue. I have several working Fitnesse tests which insert data in a database, then test my full MVC application stack. When I try to add 2 Component property mappings to my entity map, I get an error saying "Unable to…
3
votes
1 answer

Mapping Many-To-Many-Relation on the same table

i am using nhibernate 3.3.1 and fluent-nhibernate 1.3. I try to map the following entity with fluent: public class Person { public int Id { get; set; } public string Name { get; set; } public List Relations { get; set; } } As…
3
votes
1 answer

Many-to-One with fixed values for a missing column

I'm dealing with a legacy database that has a locked schema. The problem I'm facing is that a number of the tables are keyed off known/fixed/hard-coded entity type Id values instead of having a column values. This means that I can't use the normal…
SteveH
  • 343
  • 2
  • 10
3
votes
1 answer

order columns by name when using SchemaExport

i have a legacy db structure like table t1 ( c0 bigint, // pk c10 bigint, // deleted flag ) table t2 ( c0 bigint, // pk c1 bigint, // fk to t1.c0 c10 bigint, // deleted flag ) and classes class Entity { public virtual long Id {…
3
votes
4 answers

Fluent NHibernate without Automapping SQL Exception, Incorrect syntax near the keyword 'User'

Just starting in NHibernate and to my eye Everything seems correct but obviously is not. When I ren unit tests shown below I receive back that there is a syntax error near the keyword "User" here is my user class: namespace Users { …
3
votes
2 answers

Nhibernate: invoke stored procedure with CreateSqlQuery using already defined mapping

I Invoke a stored procedure using ISession.CreateSQLQuery. Then I use SetResultTransformer(new AliasToBeanResultTransformer(typeof(Article))).List
().ToList() The problem with this approach is that the AliasToBeanResultTransformer only…
2
votes
2 answers

Fluent NHibernate - how to create table-per-subclass mapping using a discriminator?

I've looked at a lot of questions on SO and google regarding sub-class mappings in nhibernate / fluent-nhibernate and not managed to find anyone with the same problem as me. I've followed the basic instructions from the fluent-nhibernate wiki…
2
votes
1 answer

Fluent NHibernate DateTime UTC

I would like to create a fluent nhibernate mapping to map a DateTime field in a following way: On save - Save the UTC value On read - Adjust to local time zone value What is the best way to achieve this mapping?
Alex
  • 9,250
  • 11
  • 70
  • 81
2
votes
0 answers

Reference entity with composite id

Both entity A & B's id are: CompositeId().KeyProperty(x => x.Id).KeyProperty(x => x.Type); While entity B should Reference entity A (it has a property "A" of type A). I tried: References(x => x.A).Columns("AId", "Type"); Which gave me…