3

i have a legacy db structure like

table t1
(
  c0 bigint, // pk
  c10 bigint,  // deleted flag
)

table t2
(
  c0 bigint, // pk
  c1 bigint, // fk to t1.c0
  c10 bigint,  // deleted flag
)

and classes

class Entity
{
    public virtual long Id { get; private set; }
    public virtual long Property { get; set; }
}

class Parent : Entity
{
    public virtual ICollection<Child> Childs { get; private set; }
}

class Child : Entity { }

After mapping it with MappingByCode or FNH, SchemaExport will create the columns in the wrong order.

table t2
(
  c0 bigint, // pk
  c10 bool,  // deleted flag
  c1 bigint, // fk to t1.c0
)

How can i make sure the columns are created in ascending order?

4

1 回答 1

3

在挖掘了源代码后,我想出了这个

configuration.BeforeBindMapping += (sender, e) =>
{
    // change to foreach if more than one classmapping per file
    var c = e.Mapping.RootClasses[0];
    c.Items = 
        // sort everything with a column (simple property, reference, ...)
        c.Items.OfType<IColumnsMapping>().OrderBy(cm => cm.Columns.First().name)
        // concat everything that has no column (collection, formula, ...)
        .Concat(c.Items.Where(o => !(o is IColumnsMapping))).ToArray();
};
于 2012-05-16T06:28:02.653 回答