{"id":176,"date":"2020-04-06T10:53:29","date_gmt":"2020-04-06T01:53:29","guid":{"rendered":"http:\/\/sumomo.ohwaki.jp\/wordpress\/?p=176"},"modified":"2020-04-06T10:53:29","modified_gmt":"2020-04-06T01:53:29","slug":"entity-framework-core","status":"publish","type":"post","link":"https:\/\/sumomo.ohwaki.jp\/wordpress\/?p=176","title":{"rendered":"Entity Framework Core"},"content":{"rendered":"\n<p>Entity Framework Core\u306f.NET Entity Framework\u306edotnet core\u7248\u3002<\/p>\n\n\n\n<p>\u5fc5\u8981\u30d1\u30c3\u30b1\u30fc\u30b8<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Microsoft.EntityFrameworkCore<\/li><li>\u5404DB\u306eEntityFramework\u30d7\u30ed\u30d0\u30a4\u30c0<\/li><li>Microsoft.EntityFrameworkCore.Design<\/li><li>\u5404DB\u306eEntityFramework\u30c7\u30b6\u30a4\u30ca<\/li><\/ol>\n\n\n\n<p>1,2\u306f\u5fc5\u9808\u3067\u30012\u306f\u5b9f\u969b\u306b\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u305f\u3081\u306e\u30c9\u30e9\u30a4\u30d0\u3002\u4f8b\u3048\u3070\u3001MS SQL Server\u306a\u3089\u3001Microsoft.EntityFrameworkCore.SqlServer,MySQL\u306a\u3089\u3001Pomelo.EntityFrameworkCore.MySql(\u672c\u5bb6Oracle\u306e\u30c9\u30e9\u30a4\u30d0\u306f\u5b9f\u884c\u6642\u30a8\u30e9\u30fc\u304c\u51fa\u305f-\u3082\u3046\u3001\u76f4\u3063\u305f\u304b\u306a?)\u7b49\u3002<\/p>\n\n\n\n<p>3,4\u306fC#\u30b3\u30fc\u30c9\u304b\u3089\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u30c6\u30fc\u30d6\u30eb\u3092\u30b8\u30a7\u30cd\u30ec\u30fc\u30c8\u3059\u308b\u306e\u306b\u5fc5\u8981\u3002<\/p>\n\n\n\n<p>\u306a\u304a\u3001Entity Framework\u95a2\u9023\u306eMigration\u7b49\u3092\u884c\u3046\u5834\u5408\u3001\u6700\u521d\u306b\u4e0b\u8a18\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u3001dotnet-ef\u30c4\u30fc\u30eb\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u304a\u304f\u5fc5\u8981\u304c\u3042\u308b\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dotnet tool install --global dotnet-ef<\/code><\/pre>\n\n\n\n<p>Entity\u3084DbContext\u7b49\u306e\u5b9a\u7fa9\u306f.NET Framework\u7248\u3068\u307b\u307c\u540c\u69d8\u3060\u304c\u3001DB\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u305f\u3081\u306e\u30b3\u30fc\u30c9\u304c\u5fc5\u8981\u3002<br>\u901a\u5e38\u306fDbContext\u304b\u3089\u6d3e\u751f\u3055\u305b\u305f\u30af\u30e9\u30b9\u306e\u3001OnConfiguring\u30e1\u30bd\u30c3\u30c9\u3092\u30aa\u30fc\u30d0\u30fc\u30e9\u30a4\u30c9\u3057\u3066<br>\u63a5\u7d9a\u5148\u306a\u3069\u3092\u8a2d\u5b9a\u3059\u308b\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using Microsoft.EntityFrameworkCore;\nusing Microsoft.EntityFrameworkCore.SqlServer;\n\u30fb\u30fb\u30fb\n    public class PersonDb : DbContext {\n      \u30fb\u30fb\u30fb\n        protected override void OnConfiguring(DbContextOptionsBuilder builder) {\n            builder\n                .UseSqlServer(&lt;\u63a5\u7d9a\u6587\u5b57\u5217>);\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<p>\u4e0a\u8a18\u306f\u3001MS SQL Server\u306b\u63a5\u7d9a\u3059\u308b\u305f\u3081\u306e\u8a2d\u5b9a\u3002<br>UseSqlServer\u306e\u90e8\u5206\u304c\u62e1\u5f35\u30e1\u30bd\u30c3\u30c9\u3067\u3001\u4f7f\u7528\u3059\u308b\u30d7\u30ed\u30d0\u30a4\u30c0\u306b\u3088\u308a\u7570\u306a\u308b\u3002<\/p>\n\n\n\n<p>DbContext\u3068Entity\u5b9a\u7fa9\u306e\u30b3\u30fc\u30c9\u3092\u4f5c\u6210\u3057\u3066\u3001\u4e0b\u8a18\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3059\u308b\u3053\u3068\u306b\u3088\u308a\u3001\u6307\u5b9a\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u4e0a\u306b\u30c6\u30fc\u30d6\u30eb\u304c\u4f5c\u6210\u3055\u308c\u308b\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dotnet ef migrations add &lt;\u30d0\u30fc\u30b8\u30e7\u30f3\u7b49\u5206\u304b\u308a\u3084\u3059\u3044\u540d\u524d>\ndotnet ef database update<\/code><\/pre>\n\n\n\n<p>\u203b\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306f\u4f5c\u6210\u3057\u3066\u304a\u304f\u5fc5\u8981\u3042\u308a(?)<\/p>\n\n\n\n<p>\u3061\u306a\u307f\u306b\u3001\u65e2\u5b58\u306e\u30c6\u30fc\u30d6\u30eb\u304b\u3089\u3001DbContext\u3068Entity\u30b3\u30fc\u30c9\u3092\u4f5c\u6210\u3059\u308b\u4e8b\u3082\u53ef\u80fd\u3002<\/p>\n\n\n\n<p>dotnet ef dbcontext scaffold &lt;\u63a5\u7d9a\u6587\u5b57\u5217> &lt;\u30d7\u30ed\u30d0\u30a4\u30c0><br>\u4f8b)<br>dotnet ef dbcontext scaffold &#8220;Data Source=\u30fb\u30fb\u30fb&#8221; Microsoft.EntityFrameworkCore.SqlServer<\/p>\n\n\n\n<p>\u4e0a\u8a18\u306b\u3088\u308aDbContext\u3092\u542b\u3093\u3060\u30bd\u30fc\u30b9,Entity\u6bce\u306e\u30bd\u30fc\u30b9\u304c\u4f5c\u6210\u3055\u308c\u308b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Entity Framework Core\u306f.NET Entity Framew &hellip; <a href=\"https:\/\/sumomo.ohwaki.jp\/wordpress\/?p=176\">\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-176","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\/176","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=176"}],"version-history":[{"count":1,"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/176\/revisions"}],"predecessor-version":[{"id":177,"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/176\/revisions\/177"}],"wp:attachment":[{"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=176"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=176"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=176"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}