{"id":338,"date":"2021-06-10T15:42:33","date_gmt":"2021-06-10T06:42:33","guid":{"rendered":"https:\/\/sumomo.ohwaki.jp\/wordpress\/?p=338"},"modified":"2021-08-03T16:59:25","modified_gmt":"2021-08-03T07:59:25","slug":"db%e3%81%8b%e3%82%89scaffoldrazorpage","status":"publish","type":"post","link":"https:\/\/sumomo.ohwaki.jp\/wordpress\/?p=338","title":{"rendered":"DB\u304b\u3089Scaffold(RazorPage)"},"content":{"rendered":"\n<p>Visual Studio ASP.net MVC\u306b\u306f\u3001DB\u3092Scaffold\u3057\u3066CRUD\u306e\u30da\u30fc\u30b8\u3092\u81ea\u52d5\u4f5c\u6210\u3059\u308b\u6a5f\u80fd\u304c\u3042\u3063\u305f\u304c\u3001dotnet core(.NET)\u3067\u3082\u3001\u540c\u7b49\u306e\u6a5f\u80fd\u304c\u3042\u3063\u305f\u306e\u3067\u3001\u30e1\u30e2\u3002<\/p>\n\n\n\n<p>dotnet\u306eCLI\u3067DB\u3092Scaffold\u3057\u3066CRUD\u30da\u30fc\u30b8\u3092\u4f5c\u6210\u3059\u308b\u306b\u306f\u3001aspnet-codegenerator\u30c4\u30fc\u30eb\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u304c\u5fc5\u8981\u3002<\/p>\n\n\n\n<p>\u4e0b\u8a18\u3067\u3001\u30c4\u30fc\u30eb\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u304a\u304f\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism undefined-numbers lang-bash\" data-file=\"\u30c4\u30fc\u30eb\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\" data-lang=\"Bash\"><code>dotnet tool install dotnet-aspnet-codegenerator -g<\/code><\/pre><\/div>\n\n\n\n<p>\u3061\u306a\u307f\u306b\u3001\u3053\u306e\u30c4\u30fc\u30eb\u3092\u52d5\u304b\u3059\u305f\u3081\u306b\u306f\u3001\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306bMicrosoft.EntityFramework.SQLServer\u304bMicrosoft.EntityFramework.Sqlite\u30d1\u30c3\u30b1\u30fc\u30b8\u306e\u8ffd\u52a0\u304c\u5fc5\u8981\u3002(\u30c4\u30fc\u30eb\u304cMemory\u4e0a\u306b\u30c6\u30f3\u30dd\u30e9\u30ea\u306eDB\u3092\u4f5c\u6210\u3057\u3066\u4f7f\u7528\u3059\u308b\u3088\u3046\u3060)<\/p>\n\n\n\n<p>\u30c4\u30fc\u30eb\u3092\u52d5\u4f5c\u3055\u305b\u308b\u524d\u306bDbContext\u304c\u5fc5\u8981\u306b\u306a\u308b\u306e\u3067\u3001DB\u306eScaffolding\u7b49\u3067\u4f5c\u6210\u3057\u3066\u304a\u304f\u3002<\/p>\n\n\n\n<p>\u6b21\u306b\u3001\u4e0b\u8a18\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3059\u308b\u3002(Razor\u30da\u30fc\u30b8\u306e\u5834\u5408\u306e\u4f8b\u3002\u30c4\u30fc\u30eb\u5b9f\u884c\u306bSQLServer\u3067\u306f\u306a\u304f\u3001Sqlite\u3092\u4f7f\u7528\u3059\u308b\u5834\u5408\u306f -sqlite\u3082\u5fc5\u8981)<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism undefined-numbers lang-bash\" data-file=\"Scaffold\" data-lang=\"Bash\"><code>dotnet aspnet-codegenerator razorpage -m &lt;\u30e2\u30c7\u30eb(\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3)\u540d&gt; -dc &lt;\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u540d&gt; -outDir Pages\/&lt;\u51fa\u529b\u5148\u30c7\u30a3\u30ec\u30af\u30c8\u30ea&gt; -scripts<\/code><\/pre><\/div>\n\n\n\n<p>\u6307\u5b9a\u3057\u305f\u30d5\u30a9\u30eb\u30c0\u306bCURD\u30da\u30fc\u30b8\u304c\u4f5c\u6210\u3055\u308c\u308b\u3002\u3061\u306a\u307f\u306b\u3001\u6307\u5b9a\u3057\u306a\u3044\u5834\u5408\u3001\u30cd\u30fc\u30e0\u30b9\u30da\u30fc\u30b9\u306f\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u540d\u3068\u540c\u69d8\u3068\u306a\u308b\u3002<\/p>\n\n\n\n<p>\u4f5c\u6210\u3055\u308c\u305f\u30da\u30fc\u30b8\u3092\u8868\u793a\u3055\u305b\u308b\u305f\u3081\u306b\u306f\u3001Startup.cs\u306eConfigureServices\u30e1\u30bd\u30c3\u30c9\u306b\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306bDbContext\u3092\u8ffd\u52a0\u3059\u308b\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism undefined-numbers lang-csharp\" data-file=\"Startup.cs\" data-lang=\"C#\"><code>public void ConfigureServices(IServiceCollection services)\n{\n    services.AddDbContext&lt;Db\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u540d&gt;();\n    services.AddRazorPages();\n}<\/code><\/pre><\/div>\n\n\n\n<p>\u5b9f\u969b\u306b\u30da\u30fc\u30b8\u3092\u8868\u793a\u3057\u3066\u307f\u308b\u3068\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u611f\u3058\u306b\u306a\u308b\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/sumomo.ohwaki.jp\/wordpress\/wp-content\/uploads\/2021\/06\/index.png\" alt=\"\" class=\"wp-image-339\" width=\"394\" height=\"193\" srcset=\"https:\/\/sumomo.ohwaki.jp\/wordpress\/wp-content\/uploads\/2021\/06\/index.png 903w, https:\/\/sumomo.ohwaki.jp\/wordpress\/wp-content\/uploads\/2021\/06\/index-300x148.png 300w, https:\/\/sumomo.ohwaki.jp\/wordpress\/wp-content\/uploads\/2021\/06\/index-768x378.png 768w\" sizes=\"auto, (max-width: 394px) 100vw, 394px\" \/><figcaption>\u4e00\u89a7<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/sumomo.ohwaki.jp\/wordpress\/wp-content\/uploads\/2021\/06\/create.png\" alt=\"\" class=\"wp-image-340\" width=\"407\" height=\"206\" srcset=\"https:\/\/sumomo.ohwaki.jp\/wordpress\/wp-content\/uploads\/2021\/06\/create.png 903w, https:\/\/sumomo.ohwaki.jp\/wordpress\/wp-content\/uploads\/2021\/06\/create-300x152.png 300w, https:\/\/sumomo.ohwaki.jp\/wordpress\/wp-content\/uploads\/2021\/06\/create-768x389.png 768w\" sizes=\"auto, (max-width: 407px) 100vw, 407px\" \/><figcaption>Create<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/sumomo.ohwaki.jp\/wordpress\/wp-content\/uploads\/2021\/06\/edit.png\" alt=\"\" class=\"wp-image-341\" width=\"421\" height=\"211\" srcset=\"https:\/\/sumomo.ohwaki.jp\/wordpress\/wp-content\/uploads\/2021\/06\/edit.png 900w, https:\/\/sumomo.ohwaki.jp\/wordpress\/wp-content\/uploads\/2021\/06\/edit-300x150.png 300w, https:\/\/sumomo.ohwaki.jp\/wordpress\/wp-content\/uploads\/2021\/06\/edit-768x384.png 768w\" sizes=\"auto, (max-width: 421px) 100vw, 421px\" \/><figcaption>Edit<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/sumomo.ohwaki.jp\/wordpress\/wp-content\/uploads\/2021\/06\/del.png\" alt=\"\" class=\"wp-image-342\" width=\"425\" height=\"237\" srcset=\"https:\/\/sumomo.ohwaki.jp\/wordpress\/wp-content\/uploads\/2021\/06\/del.png 899w, https:\/\/sumomo.ohwaki.jp\/wordpress\/wp-content\/uploads\/2021\/06\/del-300x167.png 300w, https:\/\/sumomo.ohwaki.jp\/wordpress\/wp-content\/uploads\/2021\/06\/del-768x428.png 768w\" sizes=\"auto, (max-width: 425px) 100vw, 425px\" \/><figcaption>Delete<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/sumomo.ohwaki.jp\/wordpress\/wp-content\/uploads\/2021\/06\/detail.png\" alt=\"\" class=\"wp-image-343\" width=\"399\" height=\"201\" srcset=\"https:\/\/sumomo.ohwaki.jp\/wordpress\/wp-content\/uploads\/2021\/06\/detail.png 898w, https:\/\/sumomo.ohwaki.jp\/wordpress\/wp-content\/uploads\/2021\/06\/detail-300x152.png 300w, https:\/\/sumomo.ohwaki.jp\/wordpress\/wp-content\/uploads\/2021\/06\/detail-768x389.png 768w\" sizes=\"auto, (max-width: 399px) 100vw, 399px\" \/><figcaption>Detail<\/figcaption><\/figure>\n\n\n\n<p>\u3061\u306a\u307f\u306b\u3001\u6587\u5b57\u5217\u306e\u6700\u5927\u9577\u3084\u5165\u529b\u30ec\u30f3\u30b8,\u5165\u529b\u5fc5\u9808\u306a\u3069\u306e\u30c1\u30a7\u30c3\u30af\u306f\u30e2\u30c7\u30eb\u306b\u5c5e\u6027\u3092\u4ed8\u3051\u3066\u304a\u3051\u3070\u3001\u81ea\u52d5\u7684\u306b\u884c\u3063\u3066\u304f\u308c\u308b\u3002<\/p>\n\n\n\n<p>\u66ab\u5b9a\u7684\u306a\u30e1\u30f3\u30c6\u30ca\u30f3\u30b9\u753b\u9762\u304c\u6b32\u3057\u3044\u6642\u306a\u3069\u306b\u306f\u4f7f\u3048\u308b\u304b\u306a\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Visual Studio ASP.net MVC\u306b\u306f\u3001DB\u3092Scaffold\u3057 &hellip; <a href=\"https:\/\/sumomo.ohwaki.jp\/wordpress\/?p=338\">\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":[12,11,14,4],"tags":[],"class_list":["post-338","post","type-post","status-publish","format-standard","hentry","category-asp-net-core","category-dotnetcore","category-entity-framework","category-4"],"_links":{"self":[{"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/338","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=338"}],"version-history":[{"count":5,"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/338\/revisions"}],"predecessor-version":[{"id":377,"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/338\/revisions\/377"}],"wp:attachment":[{"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=338"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=338"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=338"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}