{"id":23619393,"url":"https://github.com/frankodoom/mysql-entityframework-code-first","last_synced_at":"2025-08-30T22:30:27.326Z","repository":{"id":97247360,"uuid":"80910760","full_name":"frankodoom/MySQL-EntityFramework-Code-First","owner":"frankodoom","description":":satisfied:  Setting up MySQL .NET Connector using  Entity Framework Code First ","archived":false,"fork":false,"pushed_at":"2017-12-03T16:28:58.000Z","size":19,"stargazers_count":16,"open_issues_count":1,"forks_count":5,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-01T07:02:11.464Z","etag":null,"topics":["entityframework-codefirst","mysql","mysql-server"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/frankodoom.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-02-04T10:00:03.000Z","updated_at":"2024-03-15T17:15:38.000Z","dependencies_parsed_at":"2023-03-13T16:18:16.154Z","dependency_job_id":null,"html_url":"https://github.com/frankodoom/MySQL-EntityFramework-Code-First","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/frankodoom/MySQL-EntityFramework-Code-First","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frankodoom%2FMySQL-EntityFramework-Code-First","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frankodoom%2FMySQL-EntityFramework-Code-First/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frankodoom%2FMySQL-EntityFramework-Code-First/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frankodoom%2FMySQL-EntityFramework-Code-First/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/frankodoom","download_url":"https://codeload.github.com/frankodoom/MySQL-EntityFramework-Code-First/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frankodoom%2FMySQL-EntityFramework-Code-First/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272917686,"owners_count":25014933,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-30T02:00:09.474Z","response_time":77,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["entityframework-codefirst","mysql","mysql-server"],"created_at":"2024-12-27T19:51:12.407Z","updated_at":"2025-08-30T22:30:27.320Z","avatar_url":"https://github.com/frankodoom.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MySQL-EntityFramework-Code-First\n\u003cimg src=\"https://www.mysql.com/common/logos/logo-mysql-170x115.png\" height=\"100\" width=\"150\"/\u003e\n\nMySQL is a Database Management System from Oracle that currently supports Entity Framework through the MySQL ADO.NET Connector a fully-managed ADO.NET driver for MySQL.. I will go through steps in setting up MySQL with Entity framework 6.1.+ Using Visual Studio.\n#### Note: \nThis Tutorial also works with MariaDB.\n\n**PREREQUISITES**\n- Visual Studio\u003cbr/\u003e\n  Download Free Community Version Here (https://www.visualstudio.com/vs/community/)\n- MySQL Server\u003cbr/\u003e\n  Download Here (https://dev.mysql.com/downloads/installer/)\n- ADO.NET Driver for MySQL (Connector/NET)\t\n  Download Here (https://dev.mysql.com/downloads/connector/net/)\n- Microsoft Entity Framework 6.1.+\n\n**Adding Entity framework** \n\u003c/br\u003e\nDownload Entity Framework From Nugget in Visual Studio,this will automatically reference all needed Microsoft Entity Framework Assemblies in your project\n\u003c/br\u003e\n                             -OR\n    \u003c/br\u003e\nRun this command in Package Management Console to download Entity Framework \n\u003c/br\u003e\n` Pm\u003e   Install-Package EntityFramework`\n\n**Reference MySQL Assemblies** (NB.These Assemblies are Available after installing the MYSQL Connector for .Net you can also get them on Nuget)\n- MySQL.Data\n- MySQL.Data.Entity\n\n\n**Setting Up The Connection String in your `Web.Config` or `App.Config`** \u003c/br\u003e\nSet connection string to your existing MySql Database\n```\n\u003cconnectionStrings\u003e\n    \u003cadd name=\"SellRightDb\" providerName=\"MySql.Data.MySqlClient\"connectionString=\"server=localhost;userid=[your userid];password=[your password]database=sellright;persistsecurityinfo=True\"/\u003e\n  \u003c/connectionStrings\u003e\n```\n\n**Entity Framework Configuration**\n\u003cbr\u003e\nConfiguring MySQL to use Entity Framework add the block below to your `Web.config` or `App.config`\n```\n  \u003centityFramework\u003e\n    \u003cdefaultConnectionFactory type=\"System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework\"/\u003e\n    \u003cproviders\u003e\n      \u003cprovider invariantName=\"MySql.Data.MySqlClient\"\n          type=\"MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6\"/\u003e\n      \u003cprovider invariantName=\"System.Data.SqlClient\"\n          type=\"System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer\"/\u003e\n    \u003c/providers\u003e\n  \u003c/entityFramework\u003e\n```\n\nCreate A Simple Model Class\n```\n class Product\n    {\n        public int ProductId { get; set; }\n        public string ProductName { get; set; }\n        public double Price { get; set; }\n        public int Quantity { get; set; }\n    }\n```\n\n\nCreating Your DBContext Class\n\nImport Namespaces\n```\nusing System.Data.Entity;\nusing MySql.Data.Entity;\n```\nConfiguring your Db Contex Class\n```\n// Code-Based Configuration and Dependency resolution\n    [DbConfigurationType(typeof(MySqlEFConfiguration))]\n    class SellRightContext :DbContext\n    {\n      \n        //Add your Dbsets here\n        public DbSet\u003cProduct\u003eProducts { get; set; }\n\n        public SellRightContext()\n              \n           //Reference the name of your connection string\n            : base(\"SellRightDb\")\n              {\n            }\n    }`\n```\n\nNB.\n\nEnable Code First Migration\n```\nPM\u003e Enable-Migrations\n```\n\nAdd Code First Migration\n```\nPM\u003e Add-Migration [Give Your Migration Settings A name]\n```\n\nUpdate Database (Specify Verbose to see the SQL Querry that is being executed)\n```\nPM\u003e Update-Database -Verbose\n```\n\nYou should see your Product Table Created in Your MySql Server\n\n#### Note:\nIf you get a **System.TypeLoadException** when adding a migration, you should try to install a older version of the MySQL packages.\n\u003c/br\u003e\nTo do so, follow these steps:\n1. Open the Package Manager Console: **Tools \u003e NuGet Package Manager \u003e Package Manager Console**\n2. Uninstall the current Packages:\n``` \nPM\u003e Uninstall-Package MySQL.Data\nPM\u003e Uninstall-Package MySQL.Data.Entity \n```\n3. Install the older packages:\n```\nPM\u003e Install-Package MySQL.Data -Version [type in the tabulator and you'll see the available versions] `\nPM\u003e Install-Package MySQL.Data.Entity -Version [select the same version]\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrankodoom%2Fmysql-entityframework-code-first","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffrankodoom%2Fmysql-entityframework-code-first","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrankodoom%2Fmysql-entityframework-code-first/lists"}