Generate XML mappings from fluent Nhibernate

前端 未结 3 1437
Happy的楠姐
Happy的楠姐 2020-11-30 08:07

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 t

3条回答
  •  無奈伤痛
    2020-11-30 08:28

    I use (almost) this extension method to get the xbm in memory so I can view it in my test project:

       public static IDictionary LoadHBM(this FluentConfiguration cfg)
        {
            var result = new Dictionary();
            var mem = new MemoryStream();
            var writer = new StreamWriter(mem);
            var reader = new StreamReader(mem);
    
            cfg.Mappings(x =>
            {
                x.FluentMappings.ExportTo(writer);
                x.AutoMappings.ExportTo(writer);
            });
    
            cfg.BuildConfiguration();
            writer.Flush();
            mem.Seek(0, 0);
            var hbm = reader.ReadToEnd();
    
            var objects = XElement.Parse("" + hbm + "").Elements();
            objects.ToList().ForEach(x => result.Add(x.Elements().First().Attribute("name").Value, x.ToString()));
            return result;
        }
    

    Edit: Updated for FNH 1.2.

提交回复
热议问题