Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Set tablename by convention.

git-svn-id: https://fluent-nhibernate.googlecode.com/svn/trunk@140 48f0ce17-cc52-0410-af8c-857c09b6549b
  • Loading branch information...
commit ac0bdbd8343271e2c0d22b364caf7276103aff0f 1 parent 032349c
Andrew Stewart authored
View
8 src/FluentNHibernate.Testing/DomainModel/Mapping/ClassMapXmlCreationTester.cs
@@ -256,11 +256,9 @@ public void CreateDiscriminatorValueAtClassLevel()
[Test]
public void DetermineTheTableName()
{
- var map = new ClassMap<MappedObject>();
- map.TableName.ShouldEqual("[MappedObject]");
-
- map.WithTable("Different");
- map.TableName.ShouldEqual("Different");
+ new MappingTester<MappedObject>()
+ .ForMapping(m => { })
+ .Element("class").HasAttribute("table", "[MappedObject]");
}
[Test]
View
1  src/FluentNHibernate/Conventions.cs
@@ -44,6 +44,7 @@ public Conventions()
AddTypeConvention(new EnumerationTypeConvention());
}
+ public Func<Type, string> GetTableName = prop => String.Format("[{0}]", prop.Name);
public Func<PropertyInfo, string> GetPrimaryKeyName = prop => prop.Name;
public Func<PropertyInfo, string> GetForeignKeyName = prop => prop.Name + "_id";
public Func<Type, string> GetForeignKeyNameOfParent = type => type.Name + "_id";
View
4 src/FluentNHibernate/Mapping/ClassMap.cs
@@ -19,13 +19,15 @@ public class ClassMap<T> : ClassMapBase<T>, IMapping, IHasAttributes
public ClassMap()
{
defaultAccess = new DefaultAccessStrategyBuilder<T>(this);
- TableName = String.Format("[{0}]", typeof (T).Name);
}
public string TableName { get; private set; }
public XmlDocument CreateMapping(IMappingVisitor visitor)
{
+ if (String.IsNullOrEmpty(TableName))
+ TableName = visitor.Conventions.GetTableName.Invoke(typeof(T));
+
visitor.CurrentType = typeof(T);
XmlDocument document = getBaseDocument();
setHeaderValues(visitor, document);
Please sign in to comment.
Something went wrong with that request. Please try again.