如果你使用流利的NHibernate,你可以很容易地使用約定做到這一點。下面是我如何映射所有字符串爲varchar,而不是爲nvarchar:
public class PropertyConvention : IPropertyConvention
{
public void Apply(IPropertyInstance instance)
{
SetStringsAsAnsiStringByDefault(instance);
}
private void SetStringsAsAnsiStringByDefault(IPropertyInstance instance)
{
if (instance.Property.PropertyType == typeof(string))
{
instance.CustomType("AnsiString");
}
else if (instance.Property.PropertyType == typeof(char))
{
instance.CustomType("AnsiChar");
}
}
}
相信的NHibernate的後續版本已經內置了公約的支持,但文檔似乎是稀疏。這裏有一篇文章讓你開始,雖然:http://weblogs.asp.net/ricardoperes/nhibernate-conventions
來源
2014-11-10 07:09:03
cbp
我真的不需要這個答案了,我只是回去使用int標識符爲大多數事情現在。如果MariaDB有更好的支持,我會使用Guid。 – 2014-11-07 19:33:29