Created
October 1, 2011 07:08
-
-
Save anonymous/1255717 to your computer and use it in GitHub Desktop.
NH 3.2 core mapping
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //mapping | |
| public class EntityMapping<T> : ClassMapping<T> where T : IEntity | |
| { | |
| public EntityMapping() | |
| { | |
| DynamicInsert(true); | |
| DynamicUpdate(true); | |
| Lazy(false); | |
| Id(x => x.Id, mapper => mapper.Generator(Generators.Identity)); | |
| } | |
| public class UserMap : EntityMapping<Use> | |
| { | |
| public UserMap() | |
| { | |
| Property(u => u.UserName, c => { | |
| c.NotNullable(true); | |
| c.Length(32); | |
| c.UniqueKey("UQ_User_UserName"); | |
| }); | |
| Property(u => u.Password, c => | |
| { | |
| c.NotNullable(true); | |
| c.Length(64); | |
| }); | |
| Property(u => u.Salt, c => | |
| { | |
| c.NotNullable(true); | |
| c.Length(64); | |
| }); | |
| Property(u => u.Email, c => | |
| { | |
| c.NotNullable(true); | |
| c.Length(256); | |
| c.UniqueKey("UQ_User_Email"); | |
| }); | |
| Property(u => u.Locked); | |
| Property(u => u.CreatedAt); | |
| } | |
| } | |
| //building SessionFactory | |
| var mapper = new ModelMapper(); | |
| mapper.AddMappings(Assembly.GetAssembly(typeof(some nhibernate infrastructure type)).GetExportedTypes()); | |
| var domainMapping = mapper.CompileMappingForAllExplicitlyAddedEntities(); | |
| new SettingsFactory(); | |
| var cfg = new Configuration(); | |
| cfg.DataBaseIntegration(c => | |
| { | |
| c.Dialect<MsSql2008Dialect>(); | |
| c.ConnectionString = _connectionString; | |
| c.BatchSize = 100; | |
| c.KeywordsAutoImport = Hbm2DDLKeyWords.AutoQuote; | |
| }); | |
| cfg.AddMapping(domainMapping); | |
| _sessionFactory = cfg.BuildSessionFactory(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment