Hi,
I have been playing about with FluentNhibernate as part of the S#arp Architecture. Below is an example mapping.
public class EventBaseMap : ClassMap<EventBase>
{
public EventBaseMap()
{
WithTable("Event_Header");
//NotLazyLoaded();
Id(x => x.Id).WithUnsavedValue(-1).GeneratedBy.Native();
Map(x => x.Name).WithLengthOf(50).Not.Nullable();
Map(x => x.Description).WithLengthOf(255);
Map(x => x.Rating);
Map(x => x.Price);
Map(x => x.PhoneNumber).WithLengthOf(20).Not.Nullable();
Map(x => x.EmailAddress);
Map(x => x.Website);
Map(x => x.State).Not.Nullable().CustomSqlTypeIs("INT");
Component(x => x.Ages, m =>
{
m.Map(x => x.From).TheColumnNameIs("AgeFrom");
m.Map(x => x.To).TheColumnNameIs("AgeTo");
});
HasMany(x => x.Calendar).AsBag();
HasManyToMany(x => x.Tags)
.WithTableName("Event_Tags")
.WithParentKeyColumn("EventId")
.WithChildKeyColumn("TagId").AsBag();
}
}
I then use the Nhibernate schema generation to output my ddl to a file.
FileInfo t = new FileInfo(Server.MapPath("~/bin/MyDDL.sql"));
StreamWriter writer = t.CreateText();
new SchemaExport(cfg).Execute(true, false, false, true, NHibernateSession.Current.Connection, writer);
So far so good. However the generated ddl for this table doesn't match and actually contains an error.
create table Event_Header (
Id INT IDENTITY NOT NULL,
EmailAddress NVARCHAR(255) null,
PhoneNumber NVARCHAR(255) null,
State string null,
Website NVARCHAR(255) null,
Description NVARCHAR(255) null,
Name NVARCHAR(255) null,
Price DECIMAL(19,5) null,
Rating INT null,
AgeTo INT null,
AgeFrom INT null,
primary key (Id)
)
- The Enum State is represented as a string even though I tried to force it to use INT
- The phone number length does not match the mapping.
I was wondering how I go about debugging this. Is this a problem with the mapping in FluentNH or is it a problem with the schema generator. If I could output the xml produced then I could verify. Does anyone know how to do this?
Thanks,