Sure - here you go.
Here's the entity class (abbreviated):
namespace MvcDemo.Core
{
public class User : Entity
{
protected User()
{
}
public User(String userName) : this() {
UserName = userName;
}
public User(String firstName,String lastName) : this() {
FirstName = firstName;
LastName = lastName;
}
[DomainSignature]
[NotNullNotEmpty]
public virtual String UserName { get; set; }
public virtual String FirstName { get; set; }
public virtual String LastName { get; set; }
}
}
Mapping class:
namespace MvcDemo.Data.NHibernateMappings
{
public class UserMap : IAutoMappingOverride<User>
{
public void Override(AutoMap<User> mapping) {
mapping.WithTable("user_");
mapping.SetAttribute("lazy", "false");
mapping.Id(x => x.Id, "UserId");
}
}
}
Automapper config:
namespace MvcDemo.Data.NHibernateMaps
{
public class AutoPersistenceModelGenerator :
IAutoPersistenceModelGenerator
{
public AutoPersistenceModel Generate() {
AutoPersistenceModel mappings = AutoPersistenceModel
.MapEntitiesFromAssemblyOf<User>()
.Where(GetAutoMappingFilter)
.WithConvention(GetConventions)
.UseOverridesFromAssemblyOf<AutoPersistenceModelGenerator>
();
return mappings;
}
/// <summary>
/// Provides a filter for only including types which inherit
from the IEntityWithTypedId interface.
/// This might be considered a little hackish having this
magic string in the comparison, but since
/// the interface is generic, it wouldn't be possible to
compare the type directly.
/// </summary>
private bool GetAutoMappingFilter(Type t) {
return t.GetInterfaces().Any(x =>
x.IsGenericType && x.GetGenericTypeDefinition() ==
typeof(IEntityWithTypedId<>));
}
private void GetConventions(Conventions c) {
c.GetPrimaryKeyNameFromType = type => type.Name + "ID";
c.FindIdentity = type => type.Name == "Id";
c.GetTableName = type => Inflector.Net.Inflector.Pluralize
(type.Name);
c.IsBaseType = IsBaseTypeConvention;
c.GetForeignKeyNameOfParent = type => type.Name + "ID";
}
private bool IsBaseTypeConvention(Type arg) {
bool derivesFromEntity = arg == typeof(Entity);
bool derivesFromEntityWithTypedId = arg.IsGenericType &&
(arg.GetGenericTypeDefinition() == typeof
(EntityWithTypedId<>));
return derivesFromEntity || derivesFromEntityWithTypedId;
}
}
}
The test app's App.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
</configSections>
<appSettings>
<!-- Accepts a comma delimited list of assembly names containing
mapping artifacts; the ".dll" is optional -->
<add key="nhibernate.mapping.assembly" value="MvcDemo.Data" />
</appSettings>
<log4net>
<appender name="LogToFile" type="log4net.Appender.FileAppender">
<file value="../../logs/Northwind.Tests.log"/>
<appendToFile value="false"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%d [%t] %-5l - %m%n%n"/>
</layout>
</appender>
<appender name="ConsoleAppender"
type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%d [%t] %-5l - %m%n%n"/>
</layout>
</appender>
<root>
<!-- Value of priority may be ALL, DEBUG, INFO, WARN, ERROR, FATAL,
OFF -->
<priority value="DEBUG"/>
<appender-ref ref="ConsoleAppender"/>
</root>
</log4net>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="nunit.framework"
publicKeyToken="96d09a1eb7f44a77" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535"
newVersion="2.4.8.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="NHibernate"
publicKeyToken="aa95f207798dfdb4" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535"
newVersion="2.0.1.4000"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Iesi.Collections"
publicKeyToken="AA95F207798DFDB4" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535"
newVersion="1.0.1.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Hibernate.cfg.xml
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
<session-factory>
<property
name="connection.connection_string">Server=127.0.0.1;Port=5432;Database=MvcDemo;User
Id=********;Password=********;</property>
<property name="dialect">NHibernate.Dialect.PostgreSQLDialect</
property>
<property
name="connection.provider">NHibernate.Connection.DriverConnectionProvider</
property>
<property
name="connection.driver_class">NHibernate.Driver.NpgsqlDriver</
property>
<property name="connection.release_mode">on_close</property>
<property name="show_sql">true</property>
</session-factory>
</hibernate-configuration>
I'm initializing NHProf in the unit test like this since it's a single
test at the moment. I suppose I should move this to a singleton:
[TestFixtureSetUp]
public void Setup()
{
HibernatingRhinos.NHibernate.Profiler.Appender.NHibernateProfiler.Initialize
();
}
Thanks, and let me know if you need anything else.
Dave
On Jul 6, 2:33 pm, Ayende Rahien <
aye...@ayende.com> wrote:
> It is likely that you are also including another assembly when you are using
> PostgreSQLCan you post the code & config that you are using with it?