Hi
I'm having trouble with generating my schema, which is based on NH
validator definitions. I've tried using both attributes and the new
fluent validator configuration (creating definitions that inherit from
ValidationDef class) but nothing seems to work.
My entities look like this, although a bit simplified:
public class Company : BaseEntity
{
[NotNullNotEmpty, Length(10)]
public virtual string CompanyCode { get; set; }
public virtual string Name { get; set; }
[Valid]
public virtual Address Address { get; private set; }
public virtual string Phone { get; set; }
public virtual string Fax { get; set; }
public virtual ContactPerson StatisticsContact { get; private
set; }
public virtual ContactPerson AnnualAccountingContact { get;
private set; }
public virtual string BankGiroNumber { get; set; }
public virtual string PostGiroNumber { get; set; }
protected Company()
{
}
public Company(string companyCode, string name)
{
CompanyCode = companyCode;
Name = name;
}
}
public class Address : ValueObject
{
[NotNullNotEmpty, Length(100)]
public virtual string Address1 { get; private set; }
public virtual string Address2 { get; private set; }
public virtual string PostalCode { get; private set; }
public virtual string PostalCity { get; private set; }
public virtual string Country { get; private set; }
protected Address()
{
}
public Address(string address1, string address2, string
postalcode, string city, string country)
{
Address1 = address1;
Address2 = address2;
PostalCode = postalcode;
PostalCity = city;
Country = country;
}
}
As you can see, I've included the [Valid] attribute on the Address
property in Company, so it should be able to pick up the Address
component. What I'm struggling with is creating the schema constraints
for the Address. When I create constraints for the simple properties
on Company, it is able to generate the constraints.
The ddl it generates looks something like this,
create table [Company] (
Id UNIQUEIDENTIFIER not null,
Address1 NVARCHAR(255) null,
Address2 NVARCHAR(255) null,
PostalCity NVARCHAR(255) null,
PostalCode NVARCHAR(255) null,
Country NVARCHAR(255) null,
CompanyCode NVARCHAR(10) not null,
Name NVARCHAR(255) null,
Fax NVARCHAR(255) null,
Phone NVARCHAR(255) null,
PostGiroNumber NVARCHAR(255) null,
BankGiroNumber NVARCHAR(255) null,
primary key (Id)
)
The code I use to generate the schema:
var config = new NHVConfigurationBase();
config.Properties[Environment.ApplyToDDL] = "true";
config.Properties[Environment.ValidatorMode] = "UseAttribute";
config.Properties[Environment.AutoregisterListeners] = "true";
config.Mappings.Add(new MappingConfiguration
("FNH.NaturalDisastersFund.Core", null));
var engine = new ValidatorEngine();
engine.Configure(config);
var configuration = Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008.ConnectionString
(Config.ConnectionString).ShowSql)
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<CompanyMap>())
.BuildConfiguration();
configuration.Initialize(engine);
new SchemaExport(configuration).SetOutputFile(@"c:
\sqlscript.sql").Execute(true, false, false);
The strange thing is that my validation works just fine, it is just
the schema export that fails.
When I create the constraints in my NH entity mapping file, it is able
to generate the proper schema, so I'm wondering if I'm integrating NH
validator wrong.
Best regards
Henning
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---