I am running a simple .NET project with FluentNhibernate .
I followed a few examples that I found on the Internet, and this seems pretty easy to understand. I realized that if I let FluentNhibernate build my database schema (Sql Server 2000), it generates NVARCHAR fields for the string model properties.
Someone suggested that I could add a type change convention.
This bit of code works fine:
public class AnsiStringConvention : IPropertyConvention { private static Type stringType = typeof(string); public void Apply(FluentNHibernate.Conventions.Instances.IPropertyInstance instance) { if (instance.Property.PropertyType == stringType) { instance.CustomType("AnsiString"); } } }
Now my DB fields are VARCHAR, as I expected.
I needed to add a component to my class, following the DDD pattern, which I put in an address in a separate class and added it to my Customer class.
I created a separate mapping file for the address:
public class AddressMap : ComponentMap<Address> { public AddressMap() { Map(x => x.Number); Map(x => x.Street) .Length(100); Map(x => x.City) .Length(50); Map(x => x.PostCode) .Length(5); } }
Now all the fields of the Customer table are VARCHAR, but the fields of the Address component (Street, City and PostCode) are still created as NVARCHAR.
conventions nvarchar nhibernate fluent-nhibernate
Leftyx
source share