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
23
votes
3 answers

Map Enum as Int with Fluent NHibernate and NHibernate 3

I used this How do you map an enum as an int value with fluent NHibernate? to map in the past but I've recently upgraded to NHibernate 3 and this doesn't seem to work anymore. I've put breakpoints in my EnumConvention class and they're not being…
Josh Close
  • 22,935
  • 13
  • 92
  • 140
23
votes
2 answers

How to implement correctly IUserType?

I need to create a custom type for NHibernate by writing a new mapper class that implements IUserType. While it is relatively straightforward to override most of the methods and properties, I get some difficulties to understand how to deal correctly…
Yann Trevin
  • 3,823
  • 1
  • 30
  • 32
21
votes
2 answers

What's the best way to refresh entities in nhibernate

I would like to refresh an entity and all its child collections. What is the best way to do this? I'm talking about nhibernate:) I've read about session.Evict, session.Refresh... But I'm still not sure if doing like: RefreshEntity(T entity) { …
Katalonis
  • 691
  • 2
  • 6
  • 16
20
votes
1 answer

nHibernate 2.0 - mapping a composite-id *and* many-to-one relationship causes "invalid index" error

I have a problem. Imagine this data model: [Person] table has: PersonId, Name1 [Tag] table has: TagId, TagDescription [PersonTag] has: PersonId, TagId, IsActive Since [PersonTag] isn't just a simple many-to-many join table, I have all three…
joshua.ewer
  • 3,944
  • 3
  • 25
  • 35
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

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…
18
votes
5 answers

illegal access to loading collection error

I'm getting the error Illegal access to loading collection when I'm trying to get a list of variants belonging to a certain product. The NHibernate mapping is as below
Rob
  • 6,731
  • 12
  • 52
  • 90
18
votes
1 answer

property Access strategies in nhibernate

What are the access strategies that I can use in the attribute access of the nhibernate xml? Can someone point me the possible values to be used in it? A nice tutorial would be very appreciated. Thanks
marcelo-ferraz
  • 3,147
  • 4
  • 38
  • 55
18
votes
3 answers

nhibernate mapping: A collection with cascade="all-delete-orphan" was no longer referenced

I am having some probs with my fluent mappings. I have an entity with a child collection of entities i.e Event and EventItems for example. If I set my cascade mapping of the collection to AllDeleteOrphan I get the following error when saving a new…
Samuel Goldenbaum
  • 18,391
  • 17
  • 66
  • 104
18
votes
3 answers

How to map a VARCHAR(MAX) column in NHibernate hbm.xml mapping files

We have a SQL Server table with varchar and nvarchar max columns like this: CREATE TABLE [dbo].[MyTable]( : [MyBigUnicodeColumn] [nvarchar](max) NULL, [MyBigAnsiColumn] [varchar](max) NULL, : When creating the mapping (hbm.xml) files,…
Phil Haselden
  • 2,876
  • 3
  • 30
  • 25
17
votes
6 answers

NHibernate: how to enable lazy loading on one-to-one mapping

One-to-one relations within nhibernate can be lazyloaded either "false" or "proxy". I was wondering if anyone knows a way to do a lazy one-to-one mapping. I worked out a hack to achieve the same result by using a lazy set mapped to a private field,…
Casper
  • 1,242
  • 1
  • 11
  • 12
17
votes
3 answers

Generate XML mappings from fluent Nhibernate

How do I generate xml mappings files as part of my tests in MappingIntegrationTests I need to manually check if the fluent mappings correlate to the mappings in the leagcy project.
17
votes
2 answers

NHibernate dynamic-update Disadvantages?

Is there a reason not to use dynamic-insert/dynamic-update for NHibernate? The only reason I ask is that it seems to be something that I would want enabled as the default, not as something I would have to configure. Are there any gotchas to be aware…
Sam
  • 9,933
  • 12
  • 68
  • 104
17
votes
2 answers

Fluent Nhibernate left join

I want to map a class that result in a left outer join and not in an innner join. My composite user entity is made by one table ("aspnet_users") and an some optional properties in a second table (like FullName in "users"). public class UserMap :…
Ronnie
  • 4,959
  • 10
  • 51
  • 69
16
votes
1 answer

NHibernate 2.* mapping files: how to define nullable DateTime type (DateTime?)?

I know one of the breaking changes with NHibernate 2.* is that the NHibernate.Nullables are no longer supported. Therefore, what do you use in your mapping file to map the nullable DateTime? type? For i.e.: Understandably doesn't work:
Ted
  • 7,122
  • 9
  • 50
  • 76