Using dictionaries as entities
A little-known feature of NHibernate is EntityMode.Map
. In this recipe, I'll show you how we can use this feature to persist entities without classes.
Getting ready
Follow the Getting ready step in the Save entities to the database recipe in this chapter.
How to do it...
- Add a new folder named
EntityModeMap
to theSessionRecipes
project. - Add a new class named
Recipe
to the folder:using System; using System.Collections; using System.Collections.Generic; using System.Linq; using NH4CookbookHelpers; using NHibernate; using NHibernate.Cfg; namespace SessionRecipes.EntityModeMap { public class Recipe : HbmMappingRecipe { protected override void Configure(Configuration cfg) { cfg.SetProperty("default_entity_mode", "dynamic-map"); ...
Get NHibernate 4.x Cookbook - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.