Questions tagged [nhibernate-mapping]

XML mappings for the .NET framework object-relational mapper (ORM) NHibernate as created with .hbm.xml files.

NHibernate mappings done in XML files indicate how classes map to database objects. Refer to the relevant NHibernate reference section for details on how to create such mappings.

2300 questions
92
votes
3 answers

Inverse Attribute in NHibernate

How do I use the Inverse Attribute? If I am not mistaken, for one to many relationships the inverse attribute must be set to true. For many-to-many relationships, one of the entity class inverse attributes must be set to true and another set to…
Graviton
  • 81,782
  • 146
  • 424
  • 602
87
votes
2 answers

Unable to cast object of type NHibernate.Collection.Generic.PersistentGenericBag to List

I have a class called ReportRequest as: public class ReportRequest { Int32 templateId; List entityIds; public virtual Int32? Id { get; set; } public virtual Int32 TemplateId { get { return…
inutan
  • 10,558
  • 27
  • 84
  • 126
65
votes
3 answers

Which .NET data type is best for mapping the NUMBER Oracle data type in NHibernate?

I've seen some examples in which decimal is used in NHibernate projects for mapping to whole number columns in Oracle. Right now I'm using int and long in my program. What are the advantages of decimal over int/long? Does it perform better?
Ilya Kogan
  • 21,995
  • 15
  • 85
  • 141
51
votes
3 answers

nHibernate, No row with the given identifier exists

I have a mapping along the lines of this.
Craig
  • 36,306
  • 34
  • 114
  • 197
44
votes
1 answer

Fluent NHibernate: How to create one-to-many bidirectional mapping?

Basic question: How to I create a bidirectional one-to-many map in Fluent NHibernate? Details: I have a parent object with many children. In my case, it is meaningless for the child to not have a parent, so in the database, I would like the foreign…
Nathan
  • 10,593
  • 10
  • 63
  • 87
32
votes
3 answers

Difference between FluentNHibernate and NHibernate's "Mapping by Code"

I am coming from an Entity Framework and LLBL background for my ORM tools. I have been asked to build a new system based on NHibernate. I have never done so, so I am coming at it with fresh eyes. What is the difference between mapping with Fluent…
28
votes
3 answers

NHibernate DuplicateMappingException when two classes have the same name but different namespaces

I have a class in my domain model root that looks like this: namespace Domain { public class Foo { ... } } I also have another class with the same name in a different namespace: namespace Domain.SubDomain { public class Foo { ... } } For my…
cdmckay
  • 31,832
  • 25
  • 83
  • 114
27
votes
1 answer

Fluent NHibernate entity HasMany collections of different subclass types

So everything is working well with the basic discriminator mapping. I can interact directly with entities A and B without any problems. public class BaseType {} public class EntityA : BaseType {} public class EntityB : BaseType {} This maps without…
berko
  • 2,935
  • 4
  • 26
  • 31
26
votes
2 answers

How to create composite UNIQUE constraint in FluentNHibernate?

I know that I can Map(x => x.GroupName).WithUniqueConstraint() for a single property. But how do create a composite unique constraint in fluent nHibernate (where the unique constraint operates on the combination of two columns)?
Nathan
  • 10,593
  • 10
  • 63
  • 87
25
votes
5 answers

Programming to interfaces while mapping with Fluent NHibernate

I have been whipped into submission and have started learning Fluent NHibernate (no previous NHibernate experience). In my project, I am programming to interfaces to reduce coupling etc. That means pretty much "everything" refers to the interface…
Rune Jacobsen
  • 9,907
  • 11
  • 58
  • 75
25
votes
3 answers

Generate table indexes using Fluent NHibernate

Is it possible to generate table indexes along with the rest of the database schema with Fluent NHibernate? I would like to be able to generate the complete database DDL via an automated build process.
Todd Brooks
  • 1,167
  • 1
  • 13
  • 24
24
votes
5 answers

NHibernate - not-null property reference a null or transient value

I'm getting this exception (Full exception at the bottom): NHibernate.PropertyValueException was unhandled by user code Message="not-null property references a null or transient valueClearwave.Models.Encounters.Insurance.Patient" …
23
votes
2 answers

NHibernate - Updating a table with a trigger on it causes an error - Unexpected row count: 2; expected: 1

So I'm trying to update an object in my MS SQL 2005 database using NHibernate. Please keep in mind that this is a legacy database used in many live systems and I can't remove the triggers. When my data provider tries to .SaveOrUpdate() a row I get…
David P
  • 3,604
  • 3
  • 37
  • 54
23
votes
1 answer

Mapping Enum as string in NHibernate 3.2 mapping by code

Using NHibernate 3.2 mapping by code (not fluent-nhibernate), I'm trying to map an Enum field to a string column instead of the default int representation. I can't get the right syntax. For example: public class Account { public enum…
dstj
  • 4,800
  • 2
  • 39
  • 61
23
votes
3 answers

Forcing NHibernate to cascade delete before inserts

I have a parent object which has a one-to-many relationship with an ISet of child objects. The child objects have a unique constraint (PageNum and ContentID - the foreign key to the parent).
James Crowley
  • 3,911
  • 5
  • 36
  • 65
1
2 3
99 100