{"id":10634,"date":"2021-11-18T11:26:44","date_gmt":"2021-11-18T02:26:44","guid":{"rendered":"http:\/\/www.moonmile.net\/blog\/?p=10634"},"modified":"2021-11-20T00:17:12","modified_gmt":"2021-11-19T15:17:12","slug":"%e6%97%a2%e5%ad%98%e3%81%aemysql%e3%81%8b%e3%82%89ef-core%e3%81%aeentity%e3%82%92%e4%bd%9c%e6%88%90%e3%81%99%e3%82%8b","status":"publish","type":"post","link":"https:\/\/www.moonmile.net\/blog\/archives\/10634","title":{"rendered":"\u65e2\u5b58\u306eMySQL\u304b\u3089EF Core\u306eEntity\u3092\u4f5c\u6210\u3059\u308b"},"content":{"rendered":"\n<p>MySQL\u306e\u5834\u5408\u3001\u30b3\u30fc\u30c9\u30d5\u30a1\u30fc\u30b9\u30c8\u7684\u306b\u30b3\u30fc\u30c9\u304b\u3089\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u66f4\u65b0\u3057\u3066\u3044\u3051\u3070\u3088\u3044\u306e\u3067\u3059\u304c\u3001\u65e2\u5b58\u306e\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u304b\u3089 Entity \u3092\u4f5c\u308a\u305f\u3044\u3068\u304d\u304c\u3042\u308a\u307e\u3059\u3002\u307e\u3042\u3001\u5148\u65e5\u3066\u3082\u3068\u306e Redmine \u3092\u30d0\u30fc\u30b8\u30e7\u30f3\u30a2\u30c3\u30d7\u3055\u305b\u3066\u3001\u305b\u3063\u304b\u304f\u306a\u306e\u3067 .NET6 \u304b\u3089\u30a2\u30af\u30bb\u30b9\u3057\u3088\u3046\u3068\u601d\u3063\u3066\u3001\u3055\u3066\u3001\u3068\u601d\u6848\u3057\u305f\u7d4c\u904e\u3092\u6b8b\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">redmine.projects \u306e\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u30af\u30e9\u30b9\u3092\u624b\u4f5c\u696d\u3067\u4f5c\u308b<\/h2>\n\n\n\n<p>\u4e00\u756a\u624b\u3063\u53d6\u308a\u65e9\u3044\u306e\u306f\u3001\u624b\u4f5c\u696d\u3067\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u30af\u30e9\u30b9\u3092\u4f5c\u308b\u3053\u3068\u3067\u3059\u3002\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u30af\u30e9\u30b9\u306f\u5358\u7d14\u306a\u5024\u30af\u30e9\u30b9\u306a\u306e\u3067\u3001\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u4e26\u3079\u308c\u3070 ok. <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2021\/11\/image.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1008\" height=\"646\" src=\"http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2021\/11\/image.png\" alt=\"\" class=\"wp-image-10635\" srcset=\"https:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2021\/11\/image.png 1008w, https:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2021\/11\/image-300x192.png 300w, https:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2021\/11\/image-768x492.png 768w\" sizes=\"auto, (max-width: 1008px) 100vw, 1008px\" \/><\/a><\/figure>\n\n\n\n<p>MySQL Workbench \u306e\u7d50\u679c\u304b\u3089\u3001\u3061\u307e\u3061\u307e\u3068 C# \u306e\u30af\u30e9\u30b9\u3092\u4f5c\u308b\u304b\u3001\u30b9\u30ad\u30fc\u30de\u3092\u53c2\u7167\u3057\u306a\u304c\u3089\u624b\u4f5c\u696d\u3067\u4f5c\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-sql\" data-lang=\"SQL\"><code>CREATE TABLE `projects` (\n  `id` int NOT NULL AUTO_INCREMENT,\n  `name` varchar(255) NOT NULL DEFAULT &#39;&#39;,\n  `description` text,\n  `homepage` varchar(255) DEFAULT &#39;&#39;,\n  `is_public` tinyint(1) NOT NULL DEFAULT &#39;1&#39;,\n  `parent_id` int DEFAULT NULL,\n  `created_on` timestamp NULL DEFAULT NULL,\n  `updated_on` timestamp NULL DEFAULT NULL,\n  `identifier` varchar(255) DEFAULT NULL,\n  `status` int NOT NULL DEFAULT &#39;1&#39;,\n  `lft` int DEFAULT NULL,\n  `rgt` int DEFAULT NULL,\n  `inherit_members` tinyint(1) NOT NULL DEFAULT &#39;0&#39;,\n  `default_version_id` int DEFAULT NULL,\n  `default_assigned_to_id` int DEFAULT NULL,\n  PRIMARY KEY (`id`),\n  KEY `index_projects_on_lft` (`lft`),\n  KEY `index_projects_on_rgt` (`rgt`)\n) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 ;\n<\/code><\/pre><\/div>\n\n\n\n<ul class=\"wp-block-list\"><li>NULL \u8a31\u53ef\u306e\u90e8\u5206\u3092\u30c1\u30a7\u30c3\u30af<\/li><li>tinyint(1) \u3092 bool \u306b\u76f4\u3059<\/li><li>timestamp \u3092 DateTime \u3042\u308b\u3044\u306f DateTimeOffset \u306b\u76f4\u3059<\/li><li>\u4e3b\u30ad\u30fc\u306b Key \u5c5e\u6027\u3092\u3064\u3051\u308b<\/li><\/ul>\n\n\n\n<p>\u90e8\u5206\u3092\u6ce8\u610f\u3059\u308c\u3070\u6bd4\u8f03\u7684\u7c21\u5358\u306b C# \u306e\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u30af\u30e9\u30b9\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-csharp\" data-lang=\"C#\"><code>public class projects\n{\n    [Key]\n    public int id { get; set; }\n    public string name { get; set; } = &quot;&quot;;\n    public string? description { get; set; }\n    public string? homepage { get; set; }\n    public bool is_public { get; set; }\n    public int parent_id { get; set; }\n    public DateTime created_on { get; set; }\n    public DateTime updated_on { get; set; }\n    public string identifier { get; set; } = &quot;&quot;;\n    public bool status { get; set; }\n    public int? lft { get; set; }\n    public int? rgt { get; set; }\n    public int inherit_members { get; set; }\n    public int? default_version_id { get; set; }\n    public int? default_assigned_to_id { get; set; }\n}<\/code><\/pre><\/div>\n\n\n\n<p>\u500b\u4eba\u7684\u306a\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306a\u3089\u3070\u3001\u3053\u308c\u3067\u5341\u5206\u3067\u3059\uff08\u81ea\u5206\u3067\u8da3\u5473\u7684\u306b Redmine \u3092\u6271\u3046\u306b\u3082\u3053\u308c\u3067\u5341\u5206\uff09\u3002<\/p>\n\n\n\n<p>\u3057\u304b\u3057\u3001\u547d\u540d\u898f\u5247\u304c C# \u306b\u3042\u3063\u3066\u3044\u306a\u3044\u305f\u3081\u306b\u5927\u91cf\u306b\u8b66\u544a\u304c\u51fa\u307e\u3059\u3002\u3055\u3089\u306b\u3001\u4ed5\u4e8b\u3067\u4f7f\u3046\u5834\u5408\u306b\u306f\u30d7\u30ed\u30d1\u30c6\u30a3\u540d\u81ea\u4f53\u304c\u958b\u767a\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u5168\u4f53\u3067\u4f7f\u3046\u305f\u3081\u306b\u3001\u3042\u3061\u3053\u3061\u306b MySQL \u7279\u6709\u306e\u30b1\u30d0\u30d6\u30b1\u30fc\u30b9\uff08\u30a2\u30f3\u30c0\u30fc\u30b9\u30b3\u30a2\u3092\u4f7f\u3046\u547d\u540d\u6cd5\uff09\u304c\u6563\u3089\u304b\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002\u305f\u3068\u3048\u3070\u3001is_public \u3067\u306f\u306a\u304f\u3066 IsPublic \u306b\u3057\u3066\u304a\u304d\u305f\u3044\u308f\u3051\u3067\u3001\u3053\u3053\u3067 MySQL \u306e\u30ab\u30e9\u30e0\u540d\u3068 C# \u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u540d\u306e\u5909\u63db\u304c\u767a\u751f\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u540d\u524d\u306e\u5909\u63db\u306f System.ComponentModel.DataAnnotations.Schema \u306b\u3042\u308b\u5c5e\u6027\u3092\u4f7f\u3063\u3066\u5207\u308a\u66ff\u3048\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-csharp\" data-lang=\"C#\"><code>using System.ComponentModel.DataAnnotations.Schema;\n\n[Table(&quot;proejcts&quot;)]\npublic class Project\n{\n...\n    [Column(&quot;is_public&quot;)]\n    public bool IsPublic { get; set; }\n...\n}<\/code><\/pre><\/div>\n\n\n\n<p>Table \u5c5e\u6027\u3068 Column \u5c5e\u6027\u3092\u3061\u307e\u3061\u307e\u3068\u6307\u5b9a\u3057\u3066\u3044\u3051\u3070\u3001<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>MySQL \u5074\u306e\u30ab\u30e9\u30e0\u540d\u3092 Column \u3067\u6307\u5b9a<\/li><li>\u30d7\u30ed\u30d1\u30c6\u30a3\u540d\u306f C# \u306e\u547d\u540d\u898f\u7d04\u306b\u5408\u308f\u305b\u308b<\/li><\/ul>\n\n\n\n<p>\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u3061\u306a\u307f\u306b MySQL \u306e\u8a2d\u5b9a\u306b\u3088\u3063\u3066\u306f\u30c6\u30fc\u30d6\u30eb\u540d\u3084\u30ab\u30e9\u30e0\u540d\u306e\u5927\u6587\u5b57\u5c0f\u6587\u5b57\u304c\u533a\u5225\u3055\u308c\u308b\u305f\u3081\u3001\u74b0\u5883\u306b\u305d\u308d\u3048\u3088\u3046\u3068\u3059\u308b\u3068\uff08\u7279\u306b Linux\u4e0a\uff09\u3001\u3053\u306e\u5c5e\u6027\u306f\u5fc5\u9808\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3053\u308c\u3092 DbContext \u3092\u7d99\u627f\u3057\u305f\u30af\u30e9\u30b9\u306b\u8a2d\u5b9a\u3059\u308c\u3070\u3001\u81ea\u7531\u306b LINQ \u304c\u4f7f\u3048\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>public class RedmineDataContext : DbContext\n{\n    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)\n    {\n        var builder = new MySqlConnectionStringBuilder();\n        builder.Server = &quot;localhost&quot;;\n        builder.Database = &quot;redmine&quot;;\n        builder.UserID = &quot;redmine&quot;;\n        builder.Password = &quot;redmine&quot;;\n        optionsBuilder.UseMySQL(builder.ConnectionString);\n    }\n    public DbSet&lt;Project&gt; Project =&gt; Set&lt;Project&gt;();\n}<\/code><\/pre><\/div>\n\n\n\n<p>\u3055\u3066\u3001\u554f\u984c\u306f\u3053\u3053\u304b\u3089\u3001\u3053\u306e\u624b\u4f5c\u696d\u3067\u4f5c\u3063\u305f\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u30af\u30e9\u30b9\u3092\u3069\u306e\u3088\u3046\u306b\u5927\u91cf\u306b\u4f5c\u3063\u3066\u3044\u308b\u306e\u304b\uff1f\u3092\u8003\u3048\u307e\u3059\u3002\u6570\u500b\u306e\u30c6\u30fc\u30d6\u30eb\u306a\u3089\u3070\u624b\u4f5c\u696d\u3067\u4f5c\u3063\u3066\u3088\u3044\u306e\u3067\u3059\u304c\u3001\u6570\u5341\u500b\u306b\u306a\u308b\u3068\u7d50\u69cb\u5927\u5909\u3002100\u4ee5\u4e0a\u306b\u306a\u308b\u3068\u3061\u3087\u3063\u3068\u624b\u4f5c\u696d\u3067\u306f\u592a\u5200\u6253\u3061\u3067\u304d\u306a\u3044\u3002\u3057\u304b\u3082\u3001\u3044\u3064\u306e\u9593\u306b\u304b\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u307b\u3046\u304b\u3089\u66f4\u65b0\u3059\u308b\u5834\u5408\u306b\u518d\u3073\u624b\u4f5c\u696d\u306b\u5909\u3048\u3066\u3044\u304f\u306e\u306f\u3082\u3063\u3068\u5927\u5909\u306a\u4f5c\u696d\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u30b3\u30fc\u30c9\u30d5\u30a1\u30fc\u30b9\u30c8\u7684\u306b\u30b3\u30fc\u30c9\u304b\u3089\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u66f4\u65b0\uff08\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\uff09\u3057\u3066\u3044\u3051\u3070\u3044\u3044\u306e\u3067\u3059\u304c\u3001\u65e2\u5b58\u306eDB\u3092\u6271\u3046\u5834\u5408\u306b\u306f\u306a\u304b\u306a\u304b\u30b3\u30fc\u30c9\u30d5\u30a1\u30fc\u30b9\u30c8\u3068\u3044\u3046\u8a33\u306b\u306f\u3044\u304d\u307e\u305b\u3093\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u30c6\u30fc\u30d6\u30eb\u69cb\u6210\u3092\u53d6\u5f97\u3059\u308b<\/h2>\n\n\n\n<p>\u7d50\u8ad6\u304b\u3089\u8a00\u3044\u307e\u3059\u304c\u3001\u30c6\u30fc\u30d6\u30eb\u69cb\u6210\u3092\u3061\u307e\u3061\u307e\u53d6\u5f97\u3059\u308b\u3088\u308a\u3082\u3001\u300cdotnet ef dbcontext scaffold\u300d\u3067\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u30af\u30e9\u30b9\u3092\u4e00\u6c17\u306b\u4f5c\u3063\u305f\u307b\u3046\u304c\u697d\u3067\u3059\u3002dontet \u306e scaffold \u306f MySQL \u306b\u6b63\u5f0f\u306b\u306f\u5bfe\u5fdc\u3057\u3066\u3044\u306a\u3044\u3088\u3046\u306a\u306e\u3067\u3059\u304c\u3001\u4e00\u5fdc\u306f\u52d5\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">desc \u3067\u53d6\u5f97\u3059\u308b<\/h3>\n\n\n\n<p>MySQL \u306e\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u304b\u3089 desc \uff1c\u30c6\u30fc\u30d6\u30eb\u540d\uff1e \u3067\u53d6\u5f97\u304c\u53ef\u80fd\u3067\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>MariaDB [redmine]&gt; desc projects ;\n+------------------------+--------------+------+-----+---------+----------------+\n| Field                  | Type         | Null | Key | Default | Extra          |\n+------------------------+--------------+------+-----+---------+----------------+\n| id                     | int(11)      | NO   | PRI | NULL    | auto_increment |\n| name                   | varchar(255) | NO   |     |         |                |\n| description            | text         | YES  |     | NULL    |                |\n| homepage               | varchar(255) | YES  |     |         |                |\n| is_public              | tinyint(1)   | NO   |     | 1       |                |\n| parent_id              | int(11)      | YES  |     | NULL    |                |\n| created_on             | timestamp    | YES  |     | NULL    |                |\n| updated_on             | timestamp    | YES  |     | NULL    |                |\n| identifier             | varchar(255) | YES  |     | NULL    |                |\n| status                 | int(11)      | NO   |     | 1       |                |\n| lft                    | int(11)      | YES  | MUL | NULL    |                |\n| rgt                    | int(11)      | YES  | MUL | NULL    |                |\n| inherit_members        | tinyint(1)   | NO   |     | 0       |                |\n| default_version_id     | int(11)      | YES  |     | NULL    |                |\n| default_assigned_to_id | int(11)      | YES  |     | NULL    |                |\n+------------------------+--------------+------+-----+---------+----------------+\n15 rows in set (0.01 sec)\n\nMariaDB [redmine]&gt;<\/code><\/pre><\/div>\n\n\n\n<p>\u3053\u308c\u3092\u30c6\u30ad\u30b9\u30c8\u306b\u843d\u3068\u3057\u3066\u304b\u3089\u3061\u307e\u3061\u307e\u9069\u5f53\u306a\u30b9\u30af\u30ea\u30d7\u30c8\u3067\u30b3\u30f3\u30d0\u30fc\u30c8\u3057\u3066\u3082\u3088\u3044\u306e\u3067\u3059\u304c\u3001\u5b9f\u306f FromSqlRaw \u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3063\u3066\u76f4\u63a5 SQL \u6587\u3092\u5b9f\u884c\u3057\u3066\u3082\u53d6\u5f97\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-csharp\" data-lang=\"C#\"><code>public class DescResult\n{\n    [Key]\n    public string Field {  get; set; }\n    public string Type { get; set; }\n    public string Null { get; set; }\n    public string? Key { get; set; }\n    public string? Default { get; set; }\n    public string? Extra { get ; set; }\n}\n\npublic class RedmineDataContext : DbContext\n{\n...\n    public DbSet&lt;DescResult&gt; DescResult =&gt; Set&lt;DescResult&gt;();\n}\n\nvar cnn = context.Database.GetDbConnection() as MySqlConnection;\nvar result = context.DescResult.FromSqlRaw(&quot;DESC projects&quot;);\nConsole.WriteLine(&quot;\\nDESC projects&quot;);\nConsole.WriteLine(&quot;Field    Type    Null    Key Default Extra&quot;);\nforeach ( var it in result )\n{\n    Console.WriteLine($&quot;{it.Field}\\t{it.Type}\\t{it.Null}\\t{it.Key}\\t{it.Default}\\t{it.Extra}&quot;);\n}\n<\/code><\/pre><\/div>\n\n\n\n<p>DbContext \u306b DescResult \u306e\u3088\u3046\u306b\u7d50\u679c\u3092\u542b\u3081\u308b\u30af\u30e9\u30b9\u304c\u5fc5\u8981\u306b\u306a\u308b\u306e\u304c\u4e0d\u6e80\u3067\u306f\u3042\u308a\u307e\u3059\u304c\u3001\u3053\u3093\u306a\u98a8\u306b\u53d6\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2021\/11\/image-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"852\" height=\"516\" src=\"http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2021\/11\/image-1.png\" alt=\"\" class=\"wp-image-10636\" srcset=\"https:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2021\/11\/image-1.png 852w, https:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2021\/11\/image-1-300x182.png 300w, https:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2021\/11\/image-1-768x465.png 768w\" sizes=\"auto, (max-width: 852px) 100vw, 852px\" \/><\/a><\/figure>\n\n\n\n<p>\u3053\u306e\u4e2d\u8eab\u3092\u30c1\u30a7\u30c3\u30af\u3057\u3066\u81ea\u524d\u3067\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u30af\u30e9\u30b9\u3092\u53d6\u5f97\u3057\u3066\u3082\u3088\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">GetSchema \u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3046<\/h3>\n\n\n\n<p>\u5b9f\u306f DbConnection \u30af\u30e9\u30b9\u306b\u306f GetSchema \u3068\u3044\u3046\u30b9\u30ad\u30fc\u30de\uff08\u30c6\u30fc\u30d6\u30eb\u69cb\u6210\uff09\u3092\u53d6\u5f97\u3059\u308b\u305f\u3081\u306e\u4fbf\u5229\u306a\u30e1\u30bd\u30c3\u30c9\u304c\u3064\u3044\u3066\u3044\u307e\u3059\u3002\u304b\u3064\u3066 VB \u3067\u4f7f\u3063\u3066\u3044\u305f ADO \u306b\u5bfe\u3059\u308b ADOX \u306e\u3088\u3046\u306a\u3082\u306e\u3067\u3001\u5bfe\u8c61\u3068\u306a\u308b\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u69cb\u6210\u60c5\u5831\u304c\u53d6\u5f97\u3067\u304d\u307e\u3059\u3002\u3053\u308c\u306f\u3001SQL Server \u306b\u9650\u3089\u305a\u3001MySQL \u3067\u3082\u53d6\u308c\u308b\u306e\u3067\u3053\u308c\u3092\u6d3b\u7528\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>neue cc &#8211; Micro-ORM\u3068\u30c6\u30fc\u30d6\u30eb\u306e\u30af\u30e9\u30b9\u5b9a\u7fa9\u81ea\u52d5\u751f\u6210\u306b\u3064\u3044\u3066 <a href=\"http:\/\/neue.cc\/2013\/06\/30_411.html\">http:\/\/neue.cc\/2013\/06\/30_411.html<\/a><\/p>\n\n\n\n<p>\u3092\u53c2\u8003\u306b\u3057\u306a\u304c\u3089\u4f5c\u3063\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002\u3044\u307e\u3068\u306a\u3063\u3066\u306f dynamic \u3060\u3068\u8f9b\u3044\u306e\u3067\u3001\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u30af\u30e9\u30b9\u3092\u4f5c\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3068\u3053\u308d\u3067\u3001GetSchema \u306b\u6e21\u3059\u30c6\u30fc\u30d6\u30eb\u540d\uff1f\u306f\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u305d\u308c\u305e\u308c\u306b\u306a\u308b\u306e\u3067\u3001Oracle \u3068\u304b SQL Server \u306e\u5834\u5408\u306f\u72ec\u81ea\u306b\u63a2\u3055\u306a\u3044\u3068\u3044\u3051\u307e\u305b\u3093\u3002\u4ed6\u306e\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306f\u3055\u3066\u304a\u304d\u3001MySQL \u306e\u5834\u5408\u306f\u3001GetSchema(&#8220;COLUMNS&#8221;) \u3067\u69cb\u6210\u60c5\u5831\u304c\u53d6\u5f97\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u30af\u30e9\u30b9\u3092\u4f5c\u6210\u3059\u308b\u305f\u3081\u306b\uff08\u4ed5\u65b9\u304c\u306a\u304f\u624b\u4f5c\u696d\u306b\u306a\u308a\u307e\u3059\u304c\uff09\u3001\u5217\u540d\u306e\u8a73\u7d30\u304c\u5fc5\u8981\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>MySQL :: MySQL 8.0 Reference Manual :: 26.3.8 The INFORMATION_SCHEMA COLUMNS Table <a href=\"https:\/\/dev.mysql.com\/doc\/refman\/8.0\/en\/information-schema-columns-table.html\">https:\/\/dev.mysql.com\/doc\/refman\/8.0\/en\/information-schema-columns-table.html<\/a><\/p>\n\n\n\n<p>MySQL \u306e\u30de\u30cb\u30e5\u30a2\u30eb\u3092\u53c2\u7167\u3057\u306a\u304c\u3089\u3001\u3061\u307e\u3061\u307e\u3068\u4f5c\u3063\u3066\u3082\u3088\u3044\u306e\u3067\u3059\u304c\u3001desc \u30b3\u30de\u30f3\u30c9\u3067\u3082\u53d6\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>MariaDB [redmine]&gt; desc INFORMATION_SCHEMA.COLUMNS ;\n+--------------------------+---------------------+------+-----+---------+-------+\n| Field                    | Type                | Null | Key | Default | Extra |\n+--------------------------+---------------------+------+-----+---------+-------+\n| TABLE_CATALOG            | varchar(512)        | NO   |     |         |       |\n| TABLE_SCHEMA             | varchar(64)         | NO   |     |         |       |\n| TABLE_NAME               | varchar(64)         | NO   |     |         |       |\n| COLUMN_NAME              | varchar(64)         | NO   |     |         |       |\n| ORDINAL_POSITION         | bigint(21) unsigned | NO   |     | 0       |       |\n| COLUMN_DEFAULT           | longtext            | YES  |     | NULL    |       |\n| IS_NULLABLE              | varchar(3)          | NO   |     |         |       |\n| DATA_TYPE                | varchar(64)         | NO   |     |         |       |\n| CHARACTER_MAXIMUM_LENGTH | bigint(21) unsigned | YES  |     | NULL    |       |\n| CHARACTER_OCTET_LENGTH   | bigint(21) unsigned | YES  |     | NULL    |       |\n| NUMERIC_PRECISION        | bigint(21) unsigned | YES  |     | NULL    |       |\n| NUMERIC_SCALE            | bigint(21) unsigned | YES  |     | NULL    |       |\n| DATETIME_PRECISION       | bigint(21) unsigned | YES  |     | NULL    |       |\n| CHARACTER_SET_NAME       | varchar(32)         | YES  |     | NULL    |       |\n| COLLATION_NAME           | varchar(32)         | YES  |     | NULL    |       |\n| COLUMN_TYPE              | longtext            | NO   |     | NULL    |       |\n| COLUMN_KEY               | varchar(3)          | NO   |     |         |       |\n| EXTRA                    | varchar(27)         | NO   |     |         |       |\n| PRIVILEGES               | varchar(80)         | NO   |     |         |       |\n| COLUMN_COMMENT           | varchar(1024)       | NO   |     |         |       |\n+--------------------------+---------------------+------+-----+---------+-------+\n20 rows in set (0.01 sec)\n<\/code><\/pre><\/div>\n\n\n\n<ul class=\"wp-block-list\"><li>bigint(21) \u3092 System.UInt64 \u306b\u5909\u63db<\/li><\/ul>\n\n\n\n<p>\u306e\u90e8\u5206\u3092\u6ce8\u610f\u3057\u3066\u3001\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u30af\u30e9\u30b9\u3092\u4f5c\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-csharp\" data-lang=\"C#\"><code>[Table(&quot;COLUMNS&quot;, Schema = &quot;INFORMATION_SCHEMA&quot;)]\npublic class MySqlColumns\n{\n    public string TABLE_CATALOG { get; set; } = &quot;&quot;;\n    public string TABLE_SCHEMA { get; set; } = &quot;&quot;;\n    public string TABLE_NAME { get; set; } = &quot;&quot;;\n    public string COLUMN_NAME { get; set; } = &quot;&quot;;\n    public System.UInt64 ORDINAL_POSITION { get; set; }\n    public string? COLUMN_DEFAULT { get; set; }\n    public string IS_NULLABLE { get; set; } = &quot;&quot;;\n    public string DATA_TYPE { get; set; } = &quot;&quot;;\n    public System.UInt64? CHARACTER_MAXIMUM_LENGTH { get; set; }\n    public System.UInt64? NUMERIC_PRECISION { get; set; } = null;\n    public System.UInt64? NUMERIC_SCALE { get; set; } = null;\n    public System.UInt64? DATETIME_PRECISION { get; set; } = null;\n    public string? CHARACTER_SET_NAME { get; set; } = null;\n    public string? COLLATION_NAME { get; set; } = &quot;&quot;;\n    public string? COLUMN_TYPE { get; set; } = null;\n    public string COLUMN_KEY { get; set; } = &quot;&quot;;\n    public string EXTRA { get; set; } = &quot;&quot;;\n    public string PRIVILEGES { get; set; } = &quot;&quot;;\n    public string COLUMN_COMMENT { get; set; } = &quot;&quot;;\n}\n<\/code><\/pre><\/div>\n\n\n\n<p>\u3053\u308c\u3067\u3001\u76f4\u63a5 INFORMATION_SCHEMA.COLUMNS \u3092\u547c\u3073\u51fa\u3059\u304b\u3001 GetSchema(&#8220;COLUMNS&#8221;)  \u3092\u547c\u3073\u51fa\u3057\u3066\u7d50\u679c\u3092 LINQ \u3067\u691c\u7d22\u3059\u308c\u3070\u304a\u624b\u8efd\u3067\u3059\u306d\u3002\u3068\u601d\u3063\u305f\u306e\u3067\u3059\u304c\u3001\u843d\u3068\u3057\u7a74\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u306a\u305c\u304b MySQL \u306e\u5834\u5408\u306f\u3001Table \u5c5e\u6027\u3067 Schema \u3092\u5207\u308a\u66ff\u3048\u3066\u304f\u308c\u306a\u3044\u3002<\/li><li>GetSchema \u306e\u623b\u308a\u5024\u304c\u3001DataTable \u306b\u306a\u3063\u3066\u3044\u308b\u3002<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<p>\u307e\u305a\u306f\u3001DataTable \u306e\u4e2d\u8eab\u3092\u30c1\u30a7\u30c3\u30af\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-csharp\" data-lang=\"C#\"><code>Console.WriteLine(&quot;MySQL GetSchema&quot;);\nvar context = new RedmineDataContext();\nvar cn = context.Database.GetDbConnection();\ncn!.Open();\nvar t = cn.GetSchema(&quot;columns&quot;);\n\nConsole.WriteLine(&quot;columns.\u5217\u540d&quot;);\nforeach (DataColumn col in t.Columns)\n{\n    Console.WriteLine(&quot;{0} {1}&quot;, col.ColumnName, col.DataType);\n}\n\nConsole.WriteLine(&quot;\\ncolumns.rows&quot;);\nConsole.WriteLine(&quot;TABLE_NAME   COLUMN_NAME COLUMN_TYPE IS_NULLABLE COLUMN_KEY  EXTRA&quot;);\n\nforeach ( DataRow row in t.Rows )\n{\n    Console.WriteLine(&quot;{0}  {1} {2} {3} {4} {5} {6}&quot;,\n        row[&quot;TABLE_NAME&quot;],\n        row[&quot;COLUMN_NAME&quot;],\n        row[&quot;COLUMN_TYPE&quot;],\n        row[&quot;IS_NULLABLE&quot;],\n        row[&quot;COLUMN_KEY&quot;],\n        row[&quot;COLUMN_DEFAULT&quot;],\n        row[&quot;EXTRA&quot;]);\n}\n<\/code><\/pre><\/div>\n\n\n\n<p>columns \u306e\u30c6\u30fc\u30d6\u30eb\u69cb\u9020\u306f\u3001DataTable#Columns \u3092\u4f7f\u3063\u3066\u3082\u78ba\u8a8d\u304c\u3067\u304d\u307e\u3059\u3002DataRow \u306b\u3044\u3061\u3044\u3061\u30ab\u30e9\u30e0\u540d\u3092\u6307\u5b9a\u3059\u308b\u306e\u304c\u30a2\u30ec\u3067\u3059\u304c\u3001\u3072\u3068\u307e\u305a DESC \u30b3\u30de\u30f3\u30c9\u4e92\u63db\u306e\u3082\u306e\u304c\u53d6\u5f97\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">DataTable \u304b\u3089\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u3078\u5909\u63db\u3059\u308b\u62e1\u5f35\u3092\u4f5c\u308b<\/h3>\n\n\n\n<p>DataTable.Rows \u304b\u3089\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u306b\u5909\u63db\u3055\u305b\u308b\u62e1\u5f35\u30e1\u30bd\u30c3\u30c9\u3092\u4f5c\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-csharp\" data-lang=\"C#\"><code>public static class DataTableExtenstions\n{\n    \/\/\/ &lt;summary&gt;\n    \/\/\/ DataTable.Rows \u3092\u6307\u5b9a\u3057\u305f List\uff1cT\uff1e\u306b\u5909\u63db\u3059\u308b\n    \/\/\/ &lt;\/summary&gt;\n    public static List&lt;T&gt; ToList&lt;T&gt;(this DataTable src) where T : new()  \n    {\n        var items = new List&lt;T&gt;();\n        var properties = typeof(T).GetProperties();\n        \/\/ TODO: Column \u5c5e\u6027\u304c\u3042\u308c\u3070\u3001\u63a2\u7d22\u3059\u308b\u30ab\u30e9\u30e0\u540d\u3092\u5909\u66f4\u3059\u308b\n        foreach ( DataRow row in src.Rows )\n        {\n            var item = new T();\n            foreach ( var pi in properties )\n            {\n                var value = row[pi.Name];\n                if ( value == System.DBNull.Value )\n                {\n                    pi.SetValue(item, null);\n                } \n                else\n                {\n                    pi.SetValue(item, row[pi.Name]);\n                }\n            }\n            items.Add(item);\n        }\n        return items;\n    }\n}<\/code><\/pre><\/div>\n\n\n\n<p>\u672c\u5f53\u306f Column \u5c5e\u6027\u3092\u8abf\u3079\u306a\u3044\u3068\u30c0\u30e1\u306a\u306e\u3067\u3059\u304c\u3001\u3053\u308c\u306f\u5f8c\u65e5\u3002\u3072\u3068\u307e\u305a\u3001\u8a70\u3081\u8fbc\u307f\u3092\u3067\u304d\u308b ToList \u30e1\u30bd\u30c3\u30c9\u3092\u4f5c\u3063\u305f\u306e\u3067\u3001\u3053\u308c\u3092\u4f7f\u3063\u3066 LINQ \u3067\u4f7f\u3048\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-csharp\" data-lang=\"C#\"><code>var items = cn.GetSchema(&quot;columns&quot;).ToList&lt;MySqlColumns&gt;();\nConsole.WriteLine(&quot;\\nMySqlColumns&quot;);\nConsole.WriteLine(&quot;TABLE_NAME   COLUMN_NAME COLUMN_TYPE IS_NULLABLE COLUMN_KEY  EXTRA&quot;);\nitems = items.OrderBy( t =&gt; t.TABLE_NAME).ThenBy( t =&gt; t.ORDINAL_POSITION ).ToList();\n\nforeach (var it in items)\n{\n    Console.WriteLine($&quot;{it.TABLE_NAME}  {it.COLUMN_NAME} {it.COLUMN_TYPE} {it.IS_NULLABLE} {it.COLUMN_KEY} {it.COLUMN_DEFAULT} {it.EXTRA}&quot;);\n}\n<\/code><\/pre><\/div>\n\n\n\n<p>GetSchema \u306e\u623b\u308a\u5024\u306f\u3001\u30c6\u30fc\u30d6\u30eb\u540d\u7b49\u3067\u30bd\u30fc\u30c8\u3055\u308c\u3066\u3044\u306a\u3044\u306e\u3067\u3001\u30bd\u30fc\u30c8\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2021\/11\/image-3.png\"><img loading=\"lazy\" decoding=\"async\" width=\"956\" height=\"579\" src=\"http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2021\/11\/image-3.png\" alt=\"\" class=\"wp-image-10638\" srcset=\"https:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2021\/11\/image-3.png 956w, https:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2021\/11\/image-3-300x182.png 300w, https:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2021\/11\/image-3-768x465.png 768w\" sizes=\"auto, (max-width: 956px) 100vw, 956px\" \/><\/a><\/figure>\n\n\n\n<p>\u7d50\u679c\u306f DESC \u30b3\u30de\u30f3\u30c9\u3068\u4f3c\u305f\u611f\u3058\u3067\u53d6\u5f97\u3067\u304d\u307e\u3059\u3002\u591a\u5206\u3001DESC \u30b3\u30de\u30f3\u30c9\u306e\u307b\u3046\u306f\u6574\u5f62\u3057\u3066\u3044\u308b\u306e\u3067\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<p>\u3053\u308c\u3092\u4f7f\u3063\u3066 T4 \u3067\u5909\u63db\u3057\u3066\u3082\u3088\u3044\u3057\u3001\u5225\u9014\u30b3\u30de\u30f3\u30c9\u30c4\u30fc\u30eb\u3092\u4f7f\u3063\u3066 Models \u7fa4\u3092\u4f5c\u308a\u307e\u3059\u3002\u304c\u3001\u3053\u3053\u3067\u518d\u3073 dotnet ef dbcontext scaffold \u306b\u7acb\u3061\u623b\u3063\u3066\u3001\u3082\u3046\u3061\u3087\u3063\u3068\u30b9\u30a4\u30c3\u30c1\u3092\u4f7f\u3063\u305f\u3089\u4f7f\u3044\u3084\u3059\u3044\u3088\u3046\u306b\u51fa\u306a\u3044\u304b\uff1f\uff08\u7279\u306b\u547d\u540d\u898f\u7d04\u306e\u90e8\u5206\uff09\u3092\u8abf\u3079\u76f4\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"> dotnet ef dbcontext scaffold \u3092\u4f7f\u3046<\/h2>\n\n\n\n<p>\u4f7f\u3044\u65b9\u304c\u4e0b\u8a18\u306e\u30da\u30fc\u30b8\u306b\u66f8\u3044\u3066\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u30ea\u30d0\u30fc\u30b9 \u30a8\u30f3\u30b8\u30cb\u30a2\u30ea\u30f3\u30b0 &#8211; EF Core | Microsoft Docs <a href=\"https:\/\/docs.microsoft.com\/ja-jp\/ef\/core\/managing-schemas\/scaffolding?tabs=dotnet-core-cli\">https:\/\/docs.microsoft.com\/ja-jp\/ef\/core\/managing-schemas\/scaffolding?tabs=dotnet-core-cli<\/a><\/p>\n\n\n\n<p>\u66f8\u3044\u3066\u306f\u3042\u308b\u306e\u3067\u3059\u304c\u3001\u5b9f\u306b\u4f7f\u3044\u306b\u304f\u3044\u306e\u3067\u3059\u3002dotnet ef \u30b3\u30de\u30f3\u30c9\u81ea\u4f53\u304c\u30b3\u30fc\u30c9\u30d5\u30a1\u30fc\u30b9\u30c8\u306e\u305f\u3081\u306b\u30c4\u30fc\u30eb\u3068\u3044\u3046\u611f\u3058\u304c\u3059\u308b\u306e\u3067\u3001\u3042\u307e\u308a\u65e2\u5b58\u306e\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u304b\u3089\u7d30\u304b\u304f\u53d6\u5f97\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u305b\u3093\u3002\u307e\u3042\u3001\u305d\u308c\u3067\u3082\u304a\u304a\u3056\u3063\u3071\u306b\u53d6\u308c\u308c\u3070\u3044\u3044\u306e\u3067\u3001\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092 powershell \u3067\u5b9f\u884c\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3059\u308b\u3068\u304d\u306f\u3001<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Microsoft.EntityFrameworkCore.Design \u3092\u542b\u3093\u3060\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067\u3042\u308b\u3053\u3068<\/li><\/ul>\n\n\n\n<p>\u304c\u5fc5\u9808\u3067\u3059\u3002\u3082\u3068\u3082\u3068 webapi \u3084 mvc \u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306b\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u30af\u30e9\u30b9\u3092\u8ffd\u52a0\u3059\u308b\u30b3\u30de\u30f3\u30c9\u306a\u306e\u3067\u3001\u3053\u306e\u3088\u3046\u306a\u5f62\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>dotnet ef dbcontext scaffold `\n &quot;Server=localhost;User=redmine;Password=redmine;Database=redmine&quot; `\n &quot;MySql.EntityFrameworkCore&quot; `\n --data-annotations `\n -o Models `\n --table projects `\n --force\n<\/code><\/pre><\/div>\n\n\n\n<ul class=\"wp-block-list\"><li>`\uff08\u30d0\u30c3\u30af\u30af\u30a9\u30fc\u30c8\uff09\u306f\u7d99\u7d9a\u6587\u5b57\u3067\u3059<\/li><li>\u63a5\u7d9a\u6587\u5b57\u5217\u3092\u305d\u306e\u307e\u307e\u8a18\u8ff0\u3057\u307e\u3059\uff08\u3053\u308c\u304c\u7d50\u69cb\u9762\u5012\uff09<\/li><li>\u63a5\u7d9a\u3059\u308b\u305f\u3081\u306e\u30a2\u30bb\u30f3\u30d6\u30ea\u3092\u6307\u5b9a\u3002MySQL \u306e\u5834\u5408\u306f\u3001MySql.EntityFrameworkCore<\/li><li>&#8211;data-annotations C# \u3068 MySQL \u306e\u30ab\u30e9\u30e0\u540d\u306e\u5909\u63db\u3092\u5c5e\u6027\u3067\u6307\u5b9a\u3059\u308b<\/li><li>Models \u30d5\u30a9\u30eb\u30c0\u30fc\u306b\u51fa\u529b\uff08\u3053\u308c\u304c\u306a\u3044\u3068\u3001\u30ab\u30ec\u30f3\u30c8\u30d5\u30a9\u30eb\u30c0\u30fc\u306b\u3070\u3089\u307e\u304b\u308c\u308b\uff09<\/li><li>&#8211;table \u30b9\u30a4\u30c3\u30c1\u3067\u51fa\u529b\u3059\u308b\u30c6\u30fc\u30d6\u30eb\u3092\u6307\u5b9a\u3002\u6307\u5b9a\u3057\u306a\u3044\u3068\u5168\u30c6\u30fc\u30d6\u30eb\u304c\u5bfe\u8c61\u306b\u306a\u308b\u3002<\/li><li>&#8211;force \u4e0a\u66f8\u304d\u7528\u306e\u30b9\u30a4\u30c3\u30c1<\/li><\/ul>\n\n\n\n<p>&#8211;data-annotations \u304c\u809d\u3067\u3001\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u306f\u3001DbContext \u306e OnModelCreating \u306b\u3070\u3089\u3070\u3089\u3068\u8a18\u8ff0\u3055\u308c\u308b\u306e\u3067\u3059\u304c\u3001\u3053\u308c\u3092\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u30af\u30e9\u30b9\u306e\u5c5e\u6027\u306b\u5207\u308a\u66ff\u3048\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3053\u308c\u304c\u3046\u307e\u304f\u3044\u304f\u3068 Models\/Project.cs \u304c\u51fa\u529b\u3055\u308c\u307e\u3059\u3002\u3053\u306e\u90e8\u5206\u306f\u3001ASP.NET MVC \u672c\u3068\u304b Blazor\u672c\u3068\u304b\u3067\u5fc5\u305a\u51fa\u3066\u304f\u308b\u306e\u3067\u3059\u304c\u3001dotnet ef \u30b3\u30de\u30f3\u30c9\u306e\u6271\u3044\u304c\u96e3\u3057\u304f\u3066\u3001\u8e93\u304d\u3084\u3059\u3044\u3068\u3053\u308d\u3067\u3059\u3088\u306d\u3002\u306a\u3093\u3068\u304b\u4e57\u308a\u8d8a\u3048\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-csharp\" data-lang=\"C#\"><code>using System;\nusing System.Collections.Generic;\nusing System.ComponentModel.DataAnnotations;\nusing System.ComponentModel.DataAnnotations.Schema;\nusing Microsoft.EntityFrameworkCore;\n\n#nullable disable\n\nnamespace getschema.Models\n{\n    [Table(&quot;projects&quot;)]\n    [Index(nameof(Lft), Name = &quot;index_projects_on_lft&quot;)]\n    [Index(nameof(Rgt), Name = &quot;index_projects_on_rgt&quot;)]\n    public partial class Project\n    {\n        [Key]\n        [Column(&quot;id&quot;, TypeName = &quot;int(11)&quot;)]\n        public int Id { get; set; }\n        [Required]\n        [Column(&quot;name&quot;)]\n        [StringLength(255)]\n        public string Name { get; set; }\n        [Column(&quot;description&quot;)]\n        public string Description { get; set; }\n        [Column(&quot;homepage&quot;)]\n        [StringLength(255)]\n        public string Homepage { get; set; }\n        [Required]\n        [Column(&quot;is_public&quot;)]\n        public bool? IsPublic { get; set; }\n        [Column(&quot;parent_id&quot;, TypeName = &quot;int(11)&quot;)]\n        public int? ParentId { get; set; }\n        [Column(&quot;identifier&quot;)]\n        [StringLength(255)]\n        public string Identifier { get; set; }\n        [Column(&quot;status&quot;, TypeName = &quot;int(11)&quot;)]\n        public int Status { get; set; }\n        [Column(&quot;lft&quot;, TypeName = &quot;int(11)&quot;)]\n        public int? Lft { get; set; }\n        [Column(&quot;rgt&quot;, TypeName = &quot;int(11)&quot;)]\n        public int? Rgt { get; set; }\n        [Column(&quot;inherit_members&quot;)]\n        public bool InheritMembers { get; set; }\n        [Column(&quot;default_version_id&quot;, TypeName = &quot;int(11)&quot;)]\n        public int? DefaultVersionId { get; set; }\n        [Column(&quot;default_assigned_to_id&quot;, TypeName = &quot;int(11)&quot;)]\n        public int? DefaultAssignedToId { get; set; }\n    }\n}<\/code><\/pre><\/div>\n\n\n\n<p>Visual Studio 2022 \u3067\u306f\u30c7\u30d5\u30a9\u30eb\u30c8\u3067 nullable enable \u3068\u306a\u3063\u3066\u3044\u308b\u306e\u3067\u3001\u8b66\u544a\u3092\u304a\u3055\u3048\u308b\u305f\u3081\u306b\u300c#nullable disable\u300d\u304c\u8ffd\u52a0\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3059\u3079\u3066\u306e\u30ab\u30e9\u30e0\uff08\u30d7\u30ed\u30d1\u30c6\u30a3\uff09\u306bColumn\u5c5e\u6027\u304c\u3064\u3044\u3066\u3044\u308b\u306e\u3067\u3001MySQL\u3068C#\u306e\u30de\u30c3\u30d4\u30f3\u30b0\u304c\u51fa\u6765\u305f\u72b6\u614b\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u3053\u308c\u3067\u304a\u304a\u3080\u306d\u306f\u3044\u3051\u307e\u3059\u306d\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">timestamp \u306e\u30ab\u30e9\u30e0\u304c\u6d88\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u6ce8\u610f<\/h2>\n\n\n\n<p>\u30b9\u30ad\u30e3\u30d5\u30a9\u30fc\u30c9\u3057\u305f\u3068\u304d\u306b\u8b66\u544a\u304c\u51fa\u3066\u3044\u308b\u306e\u3067\u3059\u304c\u3001\u5148\u306e Project \u30af\u30e9\u30b9\u3092\u898b\u308b\u3068\u3001created_on \u3068 updated_on \u306b\u76f8\u5f53\u3059\u308b\u3082\u306e\u304c\u3042\u308a\u307e\u305b\u3093\u3002\u5b9f\u306f\u3001\u3053\u306e2\u3064\u306e\u30ab\u30e9\u30e0\u306e\u578b\u306f\u300ctimestamp\u300d\u3068\u306a\u3063\u3066\u3044\u308b\u306e\u3067\u3001C# \u306e\u578b\u306b\u81ea\u52d5\u3067\u30b3\u30f3\u30d0\u30fc\u30c8\u3057\u306a\u3044\u305f\u3081\u3001\u524a\u9664\u3055\u308c\u3066\u3057\u307e\u3063\u3066\u3044\u308b\u306e\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u4ed5\u65b9\u304c\u306a\u3044\u306e\u3067\u3001<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>timestamp \u3092 DatTime \u306b\u5909\u63db<\/li><\/ul>\n\n\n\n<p>\u3057\u305f\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u624b\u4f5c\u696d\u3067\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>MySQL \u306e\u5834\u5408\u306f\u3001\u6642\u9593\u7d61\u307f\u306e\u578b\u304c\u3044\u304f\u3064\u304b\u3063\u3066\u305d\u308c\u3092C#\u306b\u3069\u306e\u3088\u3046\u306b\u30b3\u30f3\u30d0\u30fc\u30c8\u3059\u308b\u306e\u304b\u3001\u65e5\u4ed8\u306e 0000\/00\/00 \u306f\u3069\u3046\u6271\u3046\u306e\u304b\u3001\u304c\u554f\u984c\u306b\u306a\u308b\u306e\u3067\u6ce8\u610f\u3057\u306a\u3051\u308c\u3070\u3044\u3051\u306a\u3044\u3068\u3053\u308d\u3067\u3059\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>\u3067\u3082\u3063\u3066\u3001\u3084\u3063\u3068\u3053\u3055\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u30af\u30e9\u30b9\u306e\u51fa\u529b\u306e\u76ee\u9014\u304c\u7acb\u3063\u3066\u306e\u3067\u3001\u3053\u308c gRPC \u3067\u5229\u7528\u3057\u307e\u3059\u3002\u3053\u308c\u306f\u5f8c\u65e5\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Pomelo.EntityFrameworkCore.MySql \u3092\u4f7f\u3046<\/h2>\n\n\n\n<p>\u8ffd\u8a18\u3067\u3001<\/p>\n\n\n\n<p>\u30b9\u30ad\u30e3\u30d5\u30a9\u30fc\u30c9\u3092\u4f7f\u3046\u3068\u304d\u306b\u3001Pomelo.EntityFrameworkCore.MySql \u3092\u4f7f\u3046\u3068 timestamp \u306e\u554f\u984c\u304c\u89e3\u6c7a\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>PomeloFoundation\/Pomelo.EntityFrameworkCore.MySql: Entity Framework Core provider for MySQL and MariaDB built on top of MySqlConnector <a href=\"https:\/\/github.com\/PomeloFoundation\/Pomelo.EntityFrameworkCore.MySql\">https:\/\/github.com\/PomeloFoundation\/Pomelo.EntityFrameworkCore.MySql<\/a><\/p>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>dotnet ef dbcontext scaffold `\n &quot;Server=localhost;User=redmine;Password=redmine;Database=redmine&quot; `\n &quot;Pomelo.EntityFrameworkCore.MySql&quot; `\n --data-annotations `\n -o Models `\n --table projects `\n --force<\/code><\/pre><\/div>\n\n\n\n<p>\u3053\u306e\u72b6\u614b\u3067 project.cs \u304c\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u51fa\u529b\u3055\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-csharp\" data-lang=\"C#\"><code>using System;\nusing System.Collections.Generic;\nusing System.ComponentModel.DataAnnotations;\nusing System.ComponentModel.DataAnnotations.Schema;\nusing Microsoft.EntityFrameworkCore;\n\nnamespace getschema.Models\n{\n    [Table(&quot;projects&quot;)]\n    [Index(nameof(Lft), Name = &quot;index_projects_on_lft&quot;)]\n    [Index(nameof(Rgt), Name = &quot;index_projects_on_rgt&quot;)]\n    [MySqlCharSet(&quot;utf8&quot;)]\n    [MySqlCollation(&quot;utf8_general_ci&quot;)]\n    public partial class Project\n    {\n        [Key]\n        [Column(&quot;id&quot;, TypeName = &quot;int(11)&quot;)]\n        public int Id { get; set; }\n        [Required]\n        [Column(&quot;name&quot;)]\n        [StringLength(255)]\n        public string Name { get; set; }\n        [Column(&quot;description&quot;, TypeName = &quot;text&quot;)]\n        public string Description { get; set; }\n        [Column(&quot;homepage&quot;)]\n        [StringLength(255)]\n        public string Homepage { get; set; }\n        [Required]\n        [Column(&quot;is_public&quot;)]\n        public bool? IsPublic { get; set; }\n        [Column(&quot;parent_id&quot;, TypeName = &quot;int(11)&quot;)]\n        public int? ParentId { get; set; }\n        [Column(&quot;created_on&quot;, TypeName = &quot;timestamp&quot;)]\n        public DateTime? CreatedOn { get; set; }\n        [Column(&quot;updated_on&quot;, TypeName = &quot;timestamp&quot;)]\n        public DateTime? UpdatedOn { get; set; }\n        [Column(&quot;identifier&quot;)]\n        [StringLength(255)]\n        public string Identifier { get; set; }\n        [Column(&quot;status&quot;, TypeName = &quot;int(11)&quot;)]\n        public int Status { get; set; }\n        [Column(&quot;lft&quot;, TypeName = &quot;int(11)&quot;)]\n        public int? Lft { get; set; }\n        [Column(&quot;rgt&quot;, TypeName = &quot;int(11)&quot;)]\n        public int? Rgt { get; set; }\n        [Column(&quot;inherit_members&quot;)]\n        public bool InheritMembers { get; set; }\n        [Column(&quot;default_version_id&quot;, TypeName = &quot;int(11)&quot;)]\n        public int? DefaultVersionId { get; set; }\n        [Column(&quot;default_assigned_to_id&quot;, TypeName = &quot;int(11)&quot;)]\n        public int? DefaultAssignedToId { get; set; }\n    }\n}\n<\/code><\/pre><\/div>\n\n\n\n<ul class=\"wp-block-list\"><li>#nullable disable \u306f\u624b\u4f5c\u696d\u3067\u52a0\u3048\u308b\u3002<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>MySQL\u306e\u5834\u5408\u3001\u30b3\u30fc\u30c9\u30d5\u30a1\u30fc\u30b9\u30c8\u7684\u306b\u30b3\u30fc\u30c9\u304b\u3089\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u66f4\u65b0\u3057\u3066\u3044\u3051\u3070\u3088\u3044\u306e\u3067\u3059\u304c\u3001\u65e2\u5b58\u306e\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u304b\u3089 Entity \u3092\u4f5c\u308a\u305f\u3044\u3068\u304d\u304c\u3042\u308a\u307e\u3059\u3002\u307e\u3042\u3001\u5148\u65e5\u3066\u3082\u3068\u306e Redmine \u3092\u30d0\u30fc\u30b8\u30e7\u30f3\u30a2\u30c3\u30d7\u3055\u305b\u3066\u3001\u305b\u3063 &hellip; <a href=\"https:\/\/www.moonmile.net\/blog\/archives\/10634\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-10634","post","type-post","status-publish","format-standard","hentry","category-dev"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/10634","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/comments?post=10634"}],"version-history":[{"count":3,"href":"https:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/10634\/revisions"}],"predecessor-version":[{"id":10642,"href":"https:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/10634\/revisions\/10642"}],"wp:attachment":[{"href":"https:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/media?parent=10634"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/categories?post=10634"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/tags?post=10634"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}