change custom mapping - sharp architecture/ fluent nhibernate
Posted
by csetzkorn
on Stack Overflow
See other posts from Stack Overflow
or by csetzkorn
Published on 2010-04-07T07:58:00Z
Indexed on
2010/04/07
8:03 UTC
Read the original article
Hit count: 419
fluent-nhibernate
|s#arp-architecture
I am using the sharp architecture which also deploys FNH. The db schema sql code is generated during the testing like this:
[TestFixture]
[Category("DB Tests")]
public class MappingIntegrationTests
{
[SetUp]
public virtual void SetUp()
{
string[] mappingAssemblies = RepositoryTestsHelper.GetMappingAssemblies();
configuration = NHibernateSession.Init(
new SimpleSessionStorage(),
mappingAssemblies,
new AutoPersistenceModelGenerator().Generate(),
"../../../../app/XXX.Web/NHibernate.config"); }
[TearDown]
public virtual void TearDown()
{
NHibernateSession.CloseAllSessions();
NHibernateSession.Reset();
}
[Test]
public void CanConfirmDatabaseMatchesMappings()
{
var allClassMetadata = NHibernateSession.GetDefaultSessionFactory().GetAllClassMetadata();
foreach (var entry in allClassMetadata)
{
NHibernateSession.Current.CreateCriteria(entry.Value.GetMappedClass(EntityMode.Poco))
.SetMaxResults(0).List();
}
}
/// <summary>
/// Generates and outputs the database schema SQL to the console
/// </summary>
[Test]
public void CanGenerateDatabaseSchema()
{
System.IO.TextWriter writeFile = new StreamWriter(@"d:/XXXSqlCreate.sql");
var session = NHibernateSession.GetDefaultSessionFactory().OpenSession();
new SchemaExport(configuration).Execute(true, false, false, session.Connection, writeFile);
}
private Configuration configuration;
}
I am trying to use:
using FluentNHibernate.Automapping;
using xxx.Core;
using SharpArch.Data.NHibernate.FluentNHibernate;
using FluentNHibernate.Automapping.Alterations;
namespace xxx.Data.NHibernateMaps
{
public class x : IAutoMappingOverride<x>
{
public void Override(AutoMapping<Tx> mapping)
{
mapping.Map(x => x.text,
"text").CustomSqlType("varchar(max)");
mapping.Map(x => x.url,
"url").CustomSqlType("varchar(max)");
}
}
}
To change the standard mapping of strings from NVARCHAR(255) to varchar(max). This is not picked up during the sql schema generation.
I also tried:
mapping.Map(x => x.text, "text").Length(100000);
Any ideas?
Thanks.
Christian
© Stack Overflow or respective owner