Пример #1
0
        protected override void AddMappings(Cfg.Configuration configuration)
        {
            var mapper = new ModelMapper();

            mapper.Class <Employee>(mc =>
            {
                mc.Id(x => x.Id, map =>
                {
                    map.Generator(Generators.Increment);
                    map.Column("Id");
                });
                mc.ManyToOne <EmployeeInfo>(x => x.Info, map =>
                {
                    // Columns have to be declared first otherwise other properties are reset.
                    map.Columns(x => { x.Name("COMP_ID"); },
                                x => { x.Name("PERS_ID"); });
                    map.Unique(true);
                    map.Cascade(Mapping.ByCode.Cascade.All | Mapping.ByCode.Cascade.DeleteOrphans);
                    map.NotFound(NotFoundMode.Exception);
                });
                mc.Property(x => x.Name);
            });

            mapper.Class <EmployeeInfo>(mc =>
            {
                mc.ComponentAsId <EmployeeInfo.Identifier>(x => x.Id, map =>
                {
                    map.Property(x => x.CompanyId, m => m.Column("COMPS_ID"));
                    map.Property(x => x.PersonId, m => m.Column("PERS_ID"));
                });
            });

            configuration.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities());
        }
        protected override void AddMappings(Cfg.Configuration configuration)
        {
            var mapper = new ModelMapper();

            mapper.Class <Employee>(mc =>
            {
                mc.Id(x => x.Id, m =>
                {
                    m.Generator(Generators.Increment);
                    m.Column("Id");
                });
                mc.OneToOne <EmployeeInfo>(x => x.Info, map =>
                {
                    map.Cascade(Mapping.ByCode.Cascade.All | Mapping.ByCode.Cascade.DeleteOrphans);
                    map.Constrained(false);
                });
                mc.Property(x => x.Name);
            });

            mapper.Class <EmployeeInfo>(mc =>
            {
                mc.Id(x => x.Id, map =>
                {
                    map.Generator(Generators.Assigned);
                    map.Column("Id");
                });
            });
            configuration.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities());
        }
Пример #3
0
        public static Cfg.Configuration For <T>() where T : class
        {
            var nhConf = new Cfg.Configuration();

            nhConf.DataBaseIntegration(db => db.Dialect <MsSql2005Dialect>());

            var bahs = new ModelMapper();

            bahs.Class <T>(c => c.Id("Id", idMapper => idMapper.Generator(Generators.Assigned)));
            nhConf.AddMapping(bahs.CompileMappingForAllExplicitlyAddedEntities());

            return(nhConf);
        }