Esempio n. 1
0
            protected override void Populate(
                ConventionModelMapper mapper
                )
            {
                base.Populate(mapper);

                mapper.AddMapping <CommonDomainObjects.Mapping.TemporalObject <char> >();
                mapper.AddMapping <CommonDomainObjects.Mapping.TemporalObjectVersion <char> >();
                mapper.Class <TestObject>(
                    customizeAction => customizeAction.Table(typeof(TestObject).Name));
                mapper.Subclass <TemporalTestObject>(
                    customizeAction => customizeAction.List(
                        temporalObject => temporalObject.Versions,
                        collectionMapper =>
                {
                    collectionMapper.Key(keyMapper => keyMapper.Column("TemporalObjectId"));
                    collectionMapper.Index(
                        listIndexMapper =>
                    {
                        listIndexMapper.Column("Number");
                        listIndexMapper.Base(1);
                    });
                }));
                mapper.Class <TestObjectVersion>(customizeAction => customizeAction.Table(typeof(TestObjectVersion).Name));
            }
        /// <summary>
        /// Gets a mapping that can be used with NHibernate.
        /// </summary>
        /// <param name="additionalTypes">Additional Types that are to be added to the mapping, this is useful for adding your ApplicationUser class</param>
        /// <returns></returns>
        public static HbmMapping GetIdentityMappings(System.Type[] additionalTypes)
        {
            var baseEntityToIgnore = new[] {
                typeof(NHibernate.AspNet.Identity.DomainModel.EntityWithTypedId <int>),
                typeof(NHibernate.AspNet.Identity.DomainModel.EntityWithTypedId <string>),
            };

            var allEntities = new List <System.Type> {
                typeof(IdentityUser),
                typeof(IdentityRole),
                typeof(IdentityUserLogin),
                typeof(IdentityUserClaim),
            };

            allEntities.AddRange(additionalTypes);

            var mapper = new ConventionModelMapper();

            DefineBaseClass(mapper, baseEntityToIgnore.ToArray());
            mapper.IsComponent((type, declared) => typeof(NHibernate.AspNet.Identity.DomainModel.ValueObject).IsAssignableFrom(type));

            mapper.AddMapping <IdentityUserMap>();
            mapper.AddMapping <IdentityRoleMap>();
            mapper.AddMapping <IdentityUserClaimMap>();

            return(mapper.CompileMappingFor(allEntities));
        }
Esempio n. 3
0
            protected override void Populate(
                ConventionModelMapper mapper
                )
            {
                base.Populate(mapper);

                mapper.AddMapping <CommonDomainObjects.Mapping.Taxonomy <char> >();
                mapper.AddMapping <CommonDomainObjects.Mapping.TaxonomyTerm <char> >();
            }
Esempio n. 4
0
        static Configuration BuildSessionFactory()
        {
            var config = new Configuration();

            config.SetProperties(CreateSessionFactoryDefaultProperties());
            config.SetProperty(NhCfgEnv.ConnectionString, "Data Source=db-dev4.gdepb.gov.cn;Initial Catalog=Test;Persist Security Info=True;User ID=udev;Password=devdev");
            var mapper = new ConventionModelMapper();

            mapper.AddMapping(new UserMapping());
            mapper.AddMapping(new RoleMapping());
            var mapping = mapper.CompileMappingForAllExplicitlyAddedEntities();

            config.AddMapping(mapping);
            return(config);
        }
        /// <summary>
        /// constructor configures a SessionFactory based on the configuration passed in
        /// </summary>
        private SessionFactoryProvider()
        {
            Name = "NHibernate.AspNet.Identity";

            var baseEntityToIgnore = new[] {
                typeof(SharpArch.Domain.DomainModel.Entity),
                typeof(EntityWithTypedId <int>),
                typeof(EntityWithTypedId <string>),
            };

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

            var mapper = new ConventionModelMapper();

            DefineBaseClass(mapper, baseEntityToIgnore);
            mapper.IsComponent((type, declared) => typeof(ValueObject).IsAssignableFrom(type));

            mapper.AddMapping <IdentityUserMap>();
            mapper.AddMapping <IdentityRoleMap>();
            mapper.AddMapping <IdentityUserClaimMap>();

            var mapping = mapper.CompileMappingForEach(allEntities);

            _configuration = new Configuration();
            _configuration.Configure("sqlite-nhibernate-config.xml");
            foreach (var map in mapping)
            {
                Console.WriteLine(map.AsString());
                _configuration.AddDeserializedMapping(map, null);
            }


            //log4net.Config.XmlConfigurator.Configure();
            SessionFactory = _configuration.BuildSessionFactory();
        }
Esempio n. 6
0
        public void TestExportSchemaByCode()
        {
            var config = new Configuration();

            config.Configure("MySql.cfg.xml");
            var mapper = new ConventionModelMapper();

            mapper.AddMapping(new EmployeeMapping());
            mapper.AddMapping(new StoreMapping());
            mapper.AddMapping(new ProductMapping());

            var mapping = mapper.CompileMappingForAllExplicitlyAddedEntities();

            Assert.IsNotNull(mapping);
            Console.WriteLine(mapping.AsString());
            config.AddMapping(mapping);

            // test build schema
            var schemaExport = new SchemaExport(config);

            schemaExport.SetDelimiter(";");
            //schemaExport.SetOutputFile("R:\\test.sql");
            schemaExport.Execute(true, true, false);
        }
        protected override void Populate(
            ConventionModelMapper mapper
            )
        {
            base.Populate(mapper);

            mapper.IsEntity((
                                Type type,
                                bool declared
                                ) => IsDomainObject <Guid>(type) ||
                            IsDomainObject <string>(type) ||
                            typeof(Identifiers.Identifier).IsAssignableFrom(type));

            mapper.BeforeMapJoinedSubclass += (
                IModelInspector modelInspector,
                Type type,
                IJoinedSubclassAttributesMapper joinedSubclassMapper
                ) =>
            {
                if (typeof(DomainObject <Guid>).IsAssignableFrom(type))
                {
                    joinedSubclassMapper.Key(
                        keyMapper =>
                    {
                        keyMapper.Column(columnMapper => columnMapper.Name("Id"));

                        keyMapper.ForeignKey("FK_" + type.Name + "_Id");
                    });
                }
            };

            mapper.AddMapping <GeographicRegion>();
            mapper.AddMapping <GeographicRegionIdentifier>();
            mapper.AddMapping <GeographicSubregion>();
            mapper.AddMapping <GeographicRegionHierarchy>();
            mapper.AddMapping <GeographicRegionHierarchyMember>();
            mapper.AddMapping <ClassificationScheme>();
            mapper.AddMapping <ClassificationSchemeClassifier>();
            mapper.AddMapping <Classifier>();
            mapper.AddMapping <ExclusivityClassifier>();
            mapper.AddMapping <NaicsClassifier>();
            mapper.AddMapping <RestrictedClassifier>();
            mapper.AddMapping <SponsoredClassifier>();
            mapper.AddMapping <LifeCycleStage>();
            mapper.AddMapping <CountryJoin>();
            mapper.AddMapping <SubdivisionJoin>();
            mapper.AddMapping <Currency>();
            mapper.AddMapping <Global>();
            mapper.AddMapping <Region>();
            mapper.AddMapping <SubRegion>();
            mapper.AddMapping <IntermediateRegion>();
            mapper.AddMapping <IdentificationScheme>();
            mapper.AddMapping <Identifier>();
            mapper.AddMapping <AutonomousAgent>();
            mapper.AddMapping <AutonomousAgentIdentifier>();
            mapper.AddMapping <Organisation>();
            mapper.AddMapping <OrganisationIdentifier>();
            mapper.AddMapping <OrganisationalSubUnit>();
            mapper.AddMapping <Branch>();
            mapper.AddMapping <Hierarchy>();
            mapper.AddMapping <HierarchyMember>();
            mapper.AddMapping <Person>();
            mapper.AddMapping <LegalEntity>();
            mapper.AddMapping <Role>();
            mapper.AddMapping <AutonomousAgentInRole>();
            mapper.AddMapping <PartyInRole>();
            mapper.AddMapping <OrganisationMember>();
            mapper.AddMapping <LifeCycle>();
            mapper.AddMapping <DealType>();
            mapper.AddMapping <FeeType>();
            mapper.AddMapping <FacilityType>();
        }