Tried it on all SqlServer dialects, but from the code, it’s not used in these provider.
The commit also shows only Firebird, MySql and Oracle providers that are now using the mentioned Action.
For now I created an implementation for Sql where I just override the ToCreateTableStatement myself.
Would you accept a PR where this is implemented in a more generic way?
Was thinking of this place:
adding an extra attribute in the DataAnnotation namespace (ColumnOrder for example)
checking on each property for this attribute; if found use order value (int), if not found use 99999 as value
if any order found, sort the modelDef.FieldDefinitions list before leaving the function.
As said the above implementation I now used in my custom Sql provider; it makes it possible to decide whether the inherited properties are first or last in the table creation. Let me know.
public class PocoBase
{
[PrimaryKey]
public Guid Id { get; set; }
}
public class Poco : PocoBase
{
public string Name { get; set; }
}
When you call db.CreateTableIfNotExists<Poco>(); following table is created: (pseudo)
create table Poco
(
Name varchar(8000),
Id uniqueidentifier not null
primary key
)
In this case I want the Id column to be first and then Name.
Using [DataMember(Order = 1) on the Id and [DataMember(Order = 999)] on the Name did not change the order.
But sometimes you have for example:
public class AuditBase
{
public DateTime Updated { get; set; }
}
public class Poco : AuditBase
{
public int Id { get; set; }
public string Name { get; set; }
}
and in this case you want:
create table Poco
(
Id int not null primary key,
Name varchar(8000),
DateTime datetime
)
public class PocoBase
{
[DataMember(Order = 1)]
[PrimaryKey
public Guid Id { get; set; }
}
public class Poco : PocoBase
{
[DataMember(Order = 999)]
public string Name { get; set; }
}
But adding [DataMember] on your classes also changes serialization behavior which makes serialization of fields opt-in so I don’t want to use it for OrmLite.
Since it’s rare, at this point I’ll just call a custom OrmLiteConfig.OnModelDefinitionInit callback added in this commit so you can choose to sort the field definitions using your preferred technique.