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.
Follow the Getting ready step in the Save entities to the database recipe in this chapter.
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"); } protected override void AddInitialData(ISession session) { var movieActors = new List<Dictionary<string, object>>() { new Dictionary<string, object>() { {"Actor...