Permalink
Browse files

Changed NHibernate configuration to use specific maps rather than aut…

…o mapping.
  • Loading branch information...
1 parent 166321a commit b6c34d0678b4819b52936408ddd9eadaaedd2a9b @oharab committed Aug 15, 2011
@@ -6,7 +6,7 @@ public class Survey
{
public virtual int Id { get; private set; }
public virtual string Name { get; set; }
- public virtual string Title { get; set; }
+ public virtual string Title { get; set; }
public virtual string Description { get; set; }
}
}
@@ -9,6 +9,8 @@
using OpenSurvey.Core.Model;
using Castle.Core.Configuration;
using global::NHibernate.Tool.hbm2ddl;
+ using OpenSurvey.Persistence.NHibernate.Mappings;
+ using System.Reflection;
public class FluentConfigurationBuilder : IConfigurationBuilder
@@ -25,9 +27,7 @@ public class FluentConfigurationBuilder : IConfigurationBuilder
.ShowSql()
)
.Mappings(
- m => m.AutoMappings.Add(
- AutoMap.AssemblyOf<Survey>()
- )
+ m =>m.FluentMappings.AddFromAssemblyOf<SurveyMap>()
)
.ExposeConfiguration(buildSchema)
.BuildSessionFactory();
@@ -37,7 +37,7 @@ public class FluentConfigurationBuilder : IConfigurationBuilder
private void buildSchema(global::NHibernate.Cfg.Configuration cfg)
{
new SchemaExport(cfg)
- .Create(false, true);
+ .Create(true, true);
}
@@ -17,7 +17,7 @@ public void Install(Castle.Windsor.IWindsorContainer container, Castle.MicroKern
.Register(
Component.For<ISurveyRepository>()
.ImplementedBy<NHibernateSurveyRepository>()
- .LifeStyle.PerWebRequest
+ .LifeStyle.Transient
)
;
}
@@ -0,0 +1,23 @@
+namespace OpenSurvey.Persistence.NHibernate.Mappings
+{
+ using System;
+ using FluentNHibernate.Mapping;
+ using OpenSurvey.Core.Model;
+
+ public class SurveyMap:ClassMap<Survey>
+ {
+ public SurveyMap()
+ {
+ Id(x => x.Id)
+ .GeneratedBy.Native();
+ Map(x => x.Name)
+ .Unique()
+ .Index("idxSurvey")
+ .Not.Nullable();
+ Map(x => x.Title)
+ .Not.Nullable();
+ Map(x => x.Description)
+ .Not.Nullable();
+ }
+ }
+}
@@ -70,6 +70,7 @@
</Compile>
<Compile Include="Configuration\FluentConfigurationBuilder.cs" />
<Compile Include="Configuration\NHibernateInstaller.cs" />
+ <Compile Include="Mappings\SurveyMap.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Repositories\NHibernateSurveyRepository.cs" />
</ItemGroup>
@@ -79,7 +80,9 @@
<Name>Core</Name>
</ProjectReference>
</ItemGroup>
- <ItemGroup />
+ <ItemGroup>
+ <Folder Include="Conventions\" />
+ </ItemGroup>
<Import Project="..\..\wraps\openwrap\build\OpenWrap.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Binary file not shown.
@@ -17,7 +17,7 @@
%>
<input type="text" name="Name" value="<%= Resource.Name %>" />
<input type="text" name="Title" value="<%= Resource.Title %>" />
- <textarea name="Description" rows="4" cols="20"><%= Resource.Description %></textarea>
+ <textarea name="Description" rows="4" cols="10"><%= Resource.Description %></textarea>
<input type="submit" value="Save" /> <a href="<%= Resource.CreateUri() %>">Cancel</a>
<% }
} %>

0 comments on commit b6c34d0

Please sign in to comment.