{"action":"opened","issue":{"url":"https://api.github.com/repos/linq2db/linq2db/issues/1305","repository_url":"https://api.github.com/repos/linq2db/linq2db","labels_url":"https://api.github.com/repos/linq2db/linq2db/issues/1305/labels{/name}","comments_url":"https://api.github.com/repos/linq2db/linq2db/issues/1305/comments","events_url":"https://api.github.com/repos/linq2db/linq2db/issues/1305/events","html_url":"https://github.com/linq2db/linq2db/issues/1305","id":356650972,"node_id":"MDU6SXNzdWUzNTY2NTA5NzI=","number":1305,"title":"Add Order field for ColumnAttribute to allow greater control for code-first","user":{"login":"Corey-M","id":5035006,"node_id":"MDQ6VXNlcjUwMzUwMDY=","avatar_url":"https://avatars0.githubusercontent.com/u/5035006?v=4","gravatar_id":"","url":"https://api.github.com/users/Corey-M","html_url":"https://github.com/Corey-M","followers_url":"https://api.github.com/users/Corey-M/followers","following_url":"https://api.github.com/users/Corey-M/following{/other_user}","gists_url":"https://api.github.com/users/Corey-M/gists{/gist_id}","starred_url":"https://api.github.com/users/Corey-M/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Corey-M/subscriptions","organizations_url":"https://api.github.com/users/Corey-M/orgs","repos_url":"https://api.github.com/users/Corey-M/repos","events_url":"https://api.github.com/users/Corey-M/events{/privacy}","received_events_url":"https://api.github.com/users/Corey-M/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-09-04T04:43:00Z","updated_at":"2018-09-04T04:43:00Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"I propose that we modify `LinqToDB.Mapping.ColumnAttribute` to add an `Order` property to allow specification of column order for code-first scenarios.\r\n\r\nI've been working on building a versioned record system for one of my projects.  I have a dozen tables that all start with the same fields:\r\n\r\n    RecordID INT PRIMARY KEY,\r\n    EffectiveStart DATETIME NOT NULL,\r\n    EffectiveEnd DATETIME NULL,\r\n    Key UNIQUEIDENTIFIER NOT NULL\r\n\r\nIn C# I have something like this:\r\n\r\n    public abstract class VersionedRecord\r\n    {\r\n        // SQLite ROWID proxy\r\n        [Column(IsPrimaryKey = true, SkipOnInsert = true)]\r\n        public int RecordID { get; set; }\r\n\r\n        [Column]\r\n        public DateTime EffectiveStart { get; set; }\r\n\r\n        [Column]\r\n        public DateTime? EffectiveEnd { get; set; }\r\n\r\n        [Column]\r\n        public Guid Key { get; set; }\r\n    }\r\n\r\n    [Table(\"Accounts\")]\r\n    public class Account : VersionedRecord\r\n    {\r\n        [Column, NotNull]\r\n        public string Code { get; set; }\r\n\r\n        [Column, NotNull]\r\n        public string Name { get; set; }\r\n    }\r\n\r\nWhen I create the table using `context.CreateTable<Account>();` the fields from the most-derived class are declared first.  In the case above the SQL statement looks like this:\r\n\r\n\t--  SQLite.Classic SQLite\r\n\tCREATE TABLE [Accounts]\r\n\t(\r\n\t\t[Name]           NVarChar(255)     NULL,\r\n\t\t[Code]           NVarChar(255)     NULL,\r\n\t\t[RecordID]       INTEGER       NOT NULL,\r\n\t\t[EffectiveStart] DateTime2     NOT NULL,\r\n\t\t[EffectiveEnd]   DateTime2         NULL,\r\n\t\t[Key]            Guid          NOT NULL,\r\n\t\r\n\t\tCONSTRAINT [PK_Accounts] PRIMARY KEY ([RecordID])\r\n\t)\r\n\r\n(If I were creating the table myself I'd put the `Name` and `Code` fields after the `Key` field.)\r\n\r\nWhat I would like is a way to specify the ordering of the columns independent of their position in the type(s) where they are defined.\r\n\r\nIn [`System.ComponentModel.DataAnnotations.Schema.ColumnAttribute`][1] there is an `Order` property which lets you define the order of columns.\r\n\r\nAdding the `Order` property to `LinqToDB.Mapping.ColumnAttribute` would allow the manual specification of column ordering.  Columns with unset order values would come after the columns whose order is set.  Columns with conflicting order would be sorted as per current ordering.\r\n\r\n### Environment details\r\nlinq2db version: *2.3.0*\r\nDatabase Server: *N/A*\r\nDatabase Provider: *All*\r\nOperating system: *Windows 10*\r\nFramework version: *.NET Framework 4.6*\r\n\r\n[1]: https://docs.microsoft.com/en-au/dotnet/api/system.componentmodel.dataannotations.schema.columnattribute?view=netframework-4.7.2"}}
{"actor":{"display_login":"Corey-M"}}