I can't seem to make my table's column order right with Fluent NHibernate.
Employee.cs
public class Employee : Entity
{
#region Fields
private EmployeeStatus _status;
private DateTime _created;
private DateTime? _updated;
#endregion
#region Constructor
public Employee()
{
_status = EmployeeStatus.Active;
_created = DateTime.Now;
}
#endregion
#region Properties
public virtual string FirstName { get; set; }
public virtual string MiddleName { get; set; }
public virtual string LastName { get; set; }
public virtual string FullName
{
get
{
return string.Format("{0} {1} {2}", FirstName, MiddleName, LastName);
}
}
public virtual Gender Gender { get; set; }
public virtual DateTime BirthDate { get; set; }
public virtual Address HomeAddress { get; set; }
public virtual EmployeeStatus IsActive
{
protected set { _status = value; }
get { return _status; }
}
public virtual DateTime Created
{
protected set { _created = value; }
get { return _created; }
}
public virtual DateTime? Updated
{
protected set { _updated = value; }
get { return _updated; }
}
#endregion
#region Overrides
public override string ToString()
{
return FullName;
}
#endregion
}
HomeAddress.cs
public class Address : ValueObject<Address>
{
#region Properties
public virtual string City { get; private set; }
public virtual string Zipcode { get; private set; }
public virtual string AddressLine { get; private set; }
#endregion
#region Constructor
public Address(string city, string zipcode, string addressLine)
{
City = city;
Zipcode = zipcode;
AddressLine = addressLine;
}
/// <summary>
/// Required by NHibernate
/// </summary>
protected Address() { }
#endregion
}
EmployeeMap.cs
public class EmployeeMap : ClassMap<Employee>
{
public EmployeeMap()
{
Id(x => x.Id)
.GeneratedBy.Guid();
Map(x => x.FirstName);
Map(x => x.MiddleName);
Map(x => x.LastName);
Map(x => x.BirthDate);
Component(x => x.HomeAddress, m =>
{
m.Map(x => x.City);
m.Map(x => x.Zipcode);
m.Map(x => x.AddressLine);
});
Map(x => x.IsActive);
Map(x => x.Created);
Map(x => x.Updated);
}
}
Based on above, I expected
Id
FirstName
MiddleName
LastName
BirthDate
City
Zipcode
AddressLine
IsActive
Created
Updated
but instead NHibernate outputing this :
create table `Employee` (
Id VARCHAR(40) not null,
FirstName VARCHAR(255),
MiddleName VARCHAR(255),
LastName VARCHAR(255),
BirthDate DATETIME,
IsActive INTEGER,
Created DATETIME,
Updated DATETIME,
City VARCHAR(255),
Zipcode VARCHAR(255),
AddressLine VARCHAR(255),
primary key (Id)
)
Is it possible to order table's column just from NHibernate / FluentNHibernate? Or should I create those columns structure manually in database first?
Thanks!