{"id":668,"date":"2023-03-24T11:28:09","date_gmt":"2023-03-24T02:28:09","guid":{"rendered":"https:\/\/sumomo.ohwaki.jp\/wordpress\/?p=668"},"modified":"2023-03-24T11:28:09","modified_gmt":"2023-03-24T02:28:09","slug":"%e5%88%97%e6%8c%99%e4%bd%93%e3%83%a1%e3%83%b3%e3%83%90%e3%83%bc%e3%82%92%e6%96%87%e5%ad%97%e5%88%97%e3%81%a8%e3%81%97%e3%81%a6db%e3%81%ab%e4%bf%9d%e5%ad%98","status":"publish","type":"post","link":"https:\/\/sumomo.ohwaki.jp\/wordpress\/?p=668","title":{"rendered":"\u5217\u6319\u4f53\u30e1\u30f3\u30d0\u30fc\u3092\u6587\u5b57\u5217\u3068\u3057\u3066DB\u306b\u4fdd\u5b58"},"content":{"rendered":"\n<p>Entity Framework\u3067\u5217\u6319\u4f53\u3092\u30e1\u30f3\u30d0\u30fc\u3068\u3057\u3066\u6301\u3064Entity\u3092\u30b3\u30fc\u30c9\u30d5\u30a1\u30fc\u30b9\u30c8\u306b\u3066\u3001\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u6210\u3059\u308b\u3068\u3001\u5217\u6319\u4f53\u90e8\u5206\u306f\u6574\u6570(int)\u578b\u3068\u306a\u308b\u3002\u5217\u6319\u4f53\u4e2d\u306e\u4e26\u3073\u306b\u5909\u66f4\u304c\u7121\u3051\u308c\u3070\u554f\u984c\u306b\u306a\u3089\u306a\u3044\u306e\u3060\u304c\u3001DB\u306b\u5024\u3092\u4fdd\u5b58\u3057\u305f\u5f8c\u3067\u5217\u6319\u4f53\u306e\u9806\u756a\u304c\u5909\u66f4\u3055\u308c\u3066\u3057\u307e\u3046\u3068\u9f5f\u9f6c\u304c\u767a\u751f\u3059\u308b\u3002<\/p>\n\n\n\n<p>\u5217\u6319\u4f53\u3078\u306e\u9805\u76ee\u633f\u5165\u306a\u3069\u306e\u5909\u66f4\u304c\u8003\u3048\u3089\u308c\u308b\u5834\u5408\u306b\u306f\u3001DB\u4e2d\u306b\u5217\u6319\u4f53\u30e1\u30f3\u30d0\u30fc\u540d\u3092\u6587\u5b57\u5217\u5316\u3057\u3066\u4fdd\u5b58\u3057\u305f\u65b9\u304c\u826f\u3044\u304b\u3082\u3057\u308c\u306a\u3044\u3002<\/p>\n\n\n\n<p>\u3053\u306e\u3088\u3046\u306a\u5024\u5909\u63db\u3092\u884c\u3046\u306b\u306f\u3001DbContext\u304b\u3089\u6d3e\u751f\u3055\u305b\u305f\u30af\u30e9\u30b9\u3067\u3001OnModelCreating\u3092\u30aa\u30fc\u30d0\u30fc\u30e9\u30a4\u30c9\u3057\u3066\u3001Entity\u4e2d\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u306b\u3064\u3044\u3066\u5024\u30b3\u30f3\u30d0\u30fc\u30bf\u30fc\u3092\u5b9a\u7fa9\u3059\u308c\u3070\u3088\u3044\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism undefined-numbers lang-csharp\" data-file=\"\u5024\u30b3\u30f3\u30d0\u30fc\u30bf\u30fc\u306e\u5b9a\u7fa9\" data-lang=\"C#\"><code>\/\/ Alert Level\npublic enum AlertLevel { Debug, Information, Warning, Error, Fatal }\n\/\/ Message\npublic class AlertMessage {\n    [Key]\n    public int MessaegId { get; set; }\n    public AlertLevel Level { get; set; }\n    public string Message { get; set; } = null!;\n    public DateTime LogDate { get; set; }\n}\n\/\/ DbContext\npublic class ConvTestCtx : DbContext {\n    public DbSet&lt;AlertMessage&gt; Messages { get; set; } = null!;\n\t\t\u30fb\u30fb\u30fb\n    protected override void OnModelCreating(ModelBuilder modelBuilder) {\n        modelBuilder\n            .Entity&lt;AlertMessage&gt;()\n            .Property(e =&gt; e.Level)\n            .HasConversion(\n                v=&gt;v.ToString(),    \/\/ Instance\u21d2DB\n                v=&gt;(AlertLevel)Enum.Parse(typeof(AlertLevel),v) \/\/ DB\u21d2Instance\n            );\n    }\n}<\/code><\/pre><\/div>\n\n\n\n<p>\u3053\u308c\u3067\u3001\u751f\u6210\u3055\u308c\u308b\u30c6\u30fc\u30d6\u30eb\u4f5c\u6210SQL\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism undefined-numbers lang-sql\" data-file=\"\u4f5c\u6210\u3055\u308c\u308b\u30c6\u30fc\u30d6\u30eb(SQL Server)\" data-lang=\"SQL\"><code>CREATE TABLE [Messages] (\n    [MessaegId] int NOT NULL IDENTITY,\n    [Level] nvarchar(max) NOT NULL,\n    [Message] nvarchar(max) NOT NULL,\n    [LogDate] datetime2 NOT NULL,\n    CONSTRAINT [PK_Messages] PRIMARY KEY ([MessaegId])\n);<\/code><\/pre><\/div>\n\n\n\n<p>\u3054\u89a7\u306e\u3068\u304a\u308a\u3001Level\u304cnvarchar(max)\u3068\u306a\u3063\u3066\u3044\u308b\u3002\u5b9f\u969b\u306b\u767b\u9332\u3057\u305f\u7d50\u679c\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">MessaegId Level\t       Message \t           LogDate\r\n5\t  Information  System has Started  2023\/03\/24 08:53:15\r\n6\t  Warning      Low Battery\t   2023\/03\/24 08:53:17\r\n7\t  Debug\t       Debug Message\t   2023\/03\/24 08:53:18\r<\/pre>\n\n\n\n<p>\u3066\u306a\u611f\u3058\u3067\u3001\u53cc\u65b9\u5411\u306e\u578b\u5909\u63db\u304c\u53ef\u80fd\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Entity Framework\u3067\u5217\u6319\u4f53\u3092\u30e1\u30f3\u30d0\u30fc\u3068\u3057\u3066\u6301\u3064Entity\u3092\u30b3\u30fc\u30c9 &hellip; <a href=\"https:\/\/sumomo.ohwaki.jp\/wordpress\/?p=668\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18,14,4],"tags":[],"class_list":["post-668","post","type-post","status-publish","format-standard","hentry","category-net","category-entity-framework","category-4"],"_links":{"self":[{"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/668","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=668"}],"version-history":[{"count":3,"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/668\/revisions"}],"predecessor-version":[{"id":671,"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/668\/revisions\/671"}],"wp:attachment":[{"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=668"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=668"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=668"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}