/// <summary>
        /// constructor configures a SessionFactory based on the configuration passed in
        /// </summary>
        private SessionFactoryProvider()
        {
            Name = "NHibernate.AspNetCore.Identity";

            var allEntities = new[] {
                typeof(IdentityUser),
                typeof(ApplicationUser),
                typeof(IdentityRole),
                typeof(IdentityUserClaim),
                typeof(IdentityUserToken),
                typeof(IdentityUserLogin),
            };

            var mapper = new ModelMapper();

            mapper.AddMapping <ApplicationUserMap>();
            mapper.AddMapping <IdentityUserMap>();
            mapper.AddMapping <IdentityRoleMap>();
            mapper.AddMapping <IdentityUserClaimMap>();
            mapper.AddMapping <IdentityUserTokenMap>();
            mapper.AddMapping <IdentityUserLoginMap>();

            var mapping = mapper.CompileMappingForEach(allEntities);

            this._configuration = new Configuration();
            this._configuration.Configure("sqlite-nhibernate-config.xml");
            foreach (var map in mapping)
            {
                Console.WriteLine(map.AsString());
                this._configuration.AddDeserializedMapping(map, null);
            }
            this.SessionFactory = this._configuration.BuildSessionFactory();
        }
示例#2
0
        public void CanHaveSameComponentAsIdMultipleTimesWithDifferentColumnNamesForSameProperty()
        {
            //NH-3650
            var model = new ModelMapper();

            model.AddMapping <Child1Map>();
            model.AddMapping <Child2Map>();

            var mappings = model.CompileMappingForEach(new[] { typeof(Child1), typeof(Child2) });

            var child1Mapping = mappings.ElementAt(0);

            Assert.AreEqual("city1", child1Mapping.RootClasses[0].Properties.OfType <HbmComponent>().First().Properties.OfType <HbmProperty>().Single().column);
            //next one fails
            Assert.AreEqual("key2", child1Mapping.RootClasses[0].CompositeId.Items.OfType <HbmKeyProperty>().Last().column1);

            var child2Mapping = mappings.ElementAt(1);

            Assert.AreEqual("city2", child2Mapping.RootClasses[0].Properties.OfType <HbmComponent>().First().Properties.OfType <HbmProperty>().Single().column);
            Assert.AreEqual("key2__", child2Mapping.RootClasses[0].CompositeId.Items.OfType <HbmKeyProperty>().Last().column1);
        }