{"id":307,"date":"2021-02-25T13:40:55","date_gmt":"2021-02-25T04:40:55","guid":{"rendered":"https:\/\/sumomo.ohwaki.jp\/wordpress\/?p=307"},"modified":"2021-03-01T12:57:00","modified_gmt":"2021-03-01T03:57:00","slug":"entityframework%e4%b8%8a%e3%81%a7%e3%81%aesqlite-datetime%e3%81%ae%e6%89%b1%e3%81%84","status":"publish","type":"post","link":"https:\/\/sumomo.ohwaki.jp\/wordpress\/?p=307","title":{"rendered":"EntityFramework\u4e0a\u3067\u306eSqlite DateTime\u306e\u6271\u3044"},"content":{"rendered":"\n<p>SQLite\u3067\u306f\u3001\u65e5\u4ed8\u578b\u3068\u3044\u3046\u3082\u306e\u306f\u57fa\u672c\u7684\u306b\u5b58\u5728\u3057\u306a\u3044\u3002<\/p>\n\n\n\n<p>SQL\u306eCREATE TABLE\u4e2d\u3067\u578b\u3068\u3057\u3066DATETIME\u3092\u6307\u5b9a\u3057\u3066\u3082\u3001\u5185\u90e8\u7684\u306b\u306fBinary\u3068\u306a\u3063\u3066\u3057\u307e\u3044\u3001Scaffold\u3057\u305f\u5834\u5408\u306fbyte[]\u3068\u3057\u3066\u5909\u63db\u3055\u308c\u3066\u3057\u307e\u3046\u3002<\/p>\n\n\n\n<p>Entity Framework\u3067\u3001\u30b3\u30fc\u30c9\u30d5\u30a1\u30fc\u30b9\u30c8\u3092\u4f7f\u7528\u3057\u3066\u3001DateTime\u578b\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u3059\u308b\u3068\u3001SQLite\u4e0a\u306b\u306fTEXT\u578b\u3068\u3057\u3066\u4f5c\u6210\u3055\u308c\u3001\u81ea\u52d5\u7684\u306b\u76f8\u4e92\u5909\u63db\u3092\u304b\u3051\u308b\u3088\u3046\u306b\u8a2d\u5b9a\u3057\u3066\u304f\u308c\u308b\u3002<\/p>\n\n\n\n<p>\u305f\u3060\u3001\u30c7\u30fc\u30bf\u30d5\u30a1\u30fc\u30b9\u30c8\u3067\u3001Scaffold\u3092\u304b\u3051\u305f\u5834\u5408\u3001TEXT\u578b\u306e\u30ab\u30e9\u30e0\u304b\u3089\u4f5c\u6210\u3055\u308c\u308b\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u4e2d\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u306fstring\u578b\u306b\u306a\u3063\u3066\u3057\u307e\u3046\u3002<\/p>\n\n\n\n<p>TEXT\u578b\u3060\u304c\u3001\u5185\u5bb9\u306fDateTim\u3068\u3057\u3066\u6271\u3044\u305f\u3044\u5834\u5408\u306f\u3001DbContext\u304b\u3089\u6d3e\u751f\u3055\u305b\u305f\u30af\u30e9\u30b9\u4e2d\u3067\u3001OnModelCreating\u30e1\u30bd\u30c3\u30c9\u3092\u30aa\u30fc\u30d0\u30fc\u30e9\u30a4\u30c9\u3057\u3066\u3001\u30c7\u30fc\u30bf\u5909\u63db\u3092\u304b\u3051\u308b\u3053\u3068\u3067\u89e3\u6c7a\u3067\u304d\u308b\u3002<\/p>\n\n\n\n<p>\u4f8b\u3048\u3070\u3001\u524d\u8ff0\u306e\u65e5\u6642\u3092\u683c\u7d0d\u3059\u308bTEXT\u578b\u306e\u30ab\u30e9\u30e0\u3092DateTime\u3068\u3057\u3066\u6271\u3044\u305f\u3051\u308c\u3070\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30b3\u30fc\u30c9\u3092\u66f8\u3044\u3066\u304a\u3051\u3070\u826f\u3044\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism undefined-numbers lang-csharp\" data-file=\"\u30c7\u30fc\u30bf\u5909\u63db\u5b9a\u7fa9\" data-lang=\"C#\"><code>protected override void OnModelCreating(ModelBuilder modelBuilder)\n{\n    modelBuilder.Entity&lt;MyTable&gt;(entity =&gt;\n    {\n        entity.ToTable(&quot;MyTable&quot;);\n\n        entity.Property(e =&gt; e.PostedTime)\n            .HasColumnType(&quot;TEXT&quot;)\n            .HasColumnName(&quot;PostedTime&quot;)\n            .HasConversion&lt;DateTime&gt;();\n    });\n\n    OnModelCreatingPartial(modelBuilder);\n}<\/code><\/pre><\/div>\n\n\n\n<p>\u3053\u308c\u306b\u3088\u308a\u3001MyTable\u30c6\u30fc\u30d6\u30eb\u306ePostedTime\u306fDB\u4e0a\u306b\u306fTEXT\u578b\u3068\u3057\u3066\u4fdd\u5b58\u3055\u308c\u3001\u8aad\u307f\u51fa\u3057\u6642\u306b\u306fDateTime\u306b\u5909\u63db\u3055\u308c\u308b\u3088\u3046\u306b\u306a\u308b\u3002<\/p>\n\n\n\n<p>SQLite\u306e\u5834\u5408\u3001Migration\u3068Scaffold\u3067\u7d50\u679c\u304c\u9055\u3046\u306e\u3067\u3001\u3069\u3046\u3059\u308c\u3070\u3044\u3044\u304b\u306a\u3068\u8abf\u3079\u3066\u307f\u305f\u3002(\u3061\u306a\u307f\u306b\u3001Migration\u6642\u306b\u81ea\u52d5\u7684\u306b\u5909\u63db\u5b9a\u7fa9\u3057\u3066\u3044\u308b\u6a21\u69d8\u3002Migration\u30d5\u30a9\u30eb\u30c0\u306b\u81ea\u52d5\u751f\u6210\u3055\u308c\u3066\u3044\u308b\u3088\u3046\u3060\u3002)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>SQLite\u3067\u306f\u3001\u65e5\u4ed8\u578b\u3068\u3044\u3046\u3082\u306e\u306f\u57fa\u672c\u7684\u306b\u5b58\u5728\u3057\u306a\u3044\u3002 SQL\u306eCREATE  &hellip; <a href=\"https:\/\/sumomo.ohwaki.jp\/wordpress\/?p=307\">\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":[9,11,14,4],"tags":[],"class_list":["post-307","post","type-post","status-publish","format-standard","hentry","category-c","category-dotnetcore","category-entity-framework","category-4"],"_links":{"self":[{"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/307","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=307"}],"version-history":[{"count":6,"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/307\/revisions"}],"predecessor-version":[{"id":313,"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/307\/revisions\/313"}],"wp:attachment":[{"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=307"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=307"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=307"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}