{"id":22642531,"url":"https://github.com/anzolin/aspnetcoredappermysql","last_synced_at":"2025-04-11T23:22:37.965Z","repository":{"id":79351260,"uuid":"95059808","full_name":"anzolin/AspNetCoreDapperMySql","owner":"anzolin","description":"A project example using ASP.NET Core, Dapper ORM and MySQL.","archived":false,"fork":false,"pushed_at":"2024-01-31T13:49:30.000Z","size":612,"stargazers_count":16,"open_issues_count":0,"forks_count":15,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-25T19:13:32.431Z","etag":null,"topics":["asp-net-core","csharp","dapper","mysql","netcore"],"latest_commit_sha":null,"homepage":"","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/anzolin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2017-06-22T00:59:00.000Z","updated_at":"2024-02-02T03:38:01.000Z","dependencies_parsed_at":null,"dependency_job_id":"ee19800f-1056-4df1-87f9-47c7ef6cd1dc","html_url":"https://github.com/anzolin/AspNetCoreDapperMySql","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anzolin%2FAspNetCoreDapperMySql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anzolin%2FAspNetCoreDapperMySql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anzolin%2FAspNetCoreDapperMySql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anzolin%2FAspNetCoreDapperMySql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anzolin","download_url":"https://codeload.github.com/anzolin/AspNetCoreDapperMySql/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248493299,"owners_count":21113227,"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","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":["asp-net-core","csharp","dapper","mysql","netcore"],"created_at":"2024-12-09T05:07:13.597Z","updated_at":"2025-04-11T23:22:37.920Z","avatar_url":"https://github.com/anzolin.png","language":"HTML","funding_links":["https://www.paypal.com/donate?business=DN2VPNW42RTXY\u0026no_recurring=0\u0026currency_code=BRL","https://www.buymeacoffee.com/anzolin"],"categories":[],"sub_categories":[],"readme":"\u003c!-- PROJECT SHIELDS --\u003e\n\u003c!--\n*** I'm using markdown \"reference style\" links for readability.\n*** Reference links are enclosed in brackets [ ] instead of parentheses ( ).\n*** See the bottom of this document for the declaration of the reference variables\n*** for contributors-url, forks-url, etc. This is an optional, concise syntax you may use.\n*** https://www.markdownguide.org/basic-syntax/#reference-style-links\n--\u003e\n[![Contributors][contributors-shield]][contributors-url]\n[![Forks][forks-shield]][forks-url]\n[![Stargazers][stars-shield]][stars-url]\n[![Issues][issues-shield]][issues-url]\n[![MIT License][license-shield]][license-url]\n[![LinkedIn][linkedin-shield]][linkedin-url]\n\n---\n\n\n# ASP.NET Core, Dapper ORM and MySql\nA project example using ASP.NET Core, Dapper ORM and MySQL.\n\n\nWhat you need to do\n-------------------\n\nFirst, install the following applications:\n- [.NET Core SDK](https://www.microsoft.com/net/download/core)\n- [Visual Studio Code](https://code.visualstudio.com/)\n- [C# for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=ms-vscode.csharp)\n- [MySQL Community Edition](https://dev.mysql.com/downloads/mysql/)\n\nConsidering that you know a little about .Net Core, open the 'Visual Studio Code' and create a new .NET Core web project.\n\nApply the nuget packages listed below:\n- [Dapper](https://www.nuget.org/packages/Dapper)\n- [Dapper.Contrib](https://www.nuget.org/packages/Dapper.Contrib/)\n- [MySqlConnector](https://www.nuget.org/packages/MySqlConnector/)\n\nOpen the file 'appsettings.json' and put yours MySQL's configurations like the example below:\n\n```json\n  \"ConnectionStrings\": {\n    \"ConnectionString1\": \"host=localhost;port=3306;user id=USER;password=PASSWORD;database=DATABASENAME;\"\n  }\n```\n\nCreate a directory called 'Code' in the root folder of your project and in this folder create a class file called 'ConnectionStringList.cs' with the following content:\n\n```csharp\nnamespace AspNetCoreDapperMySql.Code\n{\n    public class ConnectionStringList\n    {\n        public string ConnectionString1 { get; set; }\n    }\n}\n```\n\nNow, create other directory called 'Models' and three classes files with the following contents:\n\n`Pais.cs`\n```csharp\nusing Dapper.Contrib.Extensions;\nusing System.Collections.Generic;\n\nnamespace AspNetCoreDapperMySql.Models\n{\n    [Table(\"GLB_Pais\")]\n    public class Pais\n    {\n        [Key]\n        public int Id { get; set; }\n        public string Nome { get; set; }\n        public ICollection\u003cUf\u003e Ufs { get; set; }\n    }\n}\n```\n\n`Uf.cs`\n```csharp\nusing Dapper.Contrib.Extensions;\nusing System.Collections.Generic;\n\nnamespace AspNetCoreDapperMySql.Models\n{\n    [Table(\"GLB_UF\")]\n    public class Uf\n    {\n        [Key]\n        public int Id { get; set; }\n        public int Id_GLB_Pais { get; set; }\n        public string Nome { get; set; }\n        public string Sigla { get; set; }\n        public Pais Pais { get; set; }\n        public ICollection\u003cCidade\u003e Cidades { get; set; }\n    }\n}\n```\n\n`Cidade.cs`\n```csharp\nusing Dapper.Contrib.Extensions;\n\nnamespace AspNetCoreDapperMySql.Models\n{\n    [Table(\"GLB_Cidade\")]\n    public class Cidade\n    {\n        [Key]\n        public int Id { get; set; }\n        public int Id_GLB_UF { get; set; }\n        public string Nome { get; set; }\n        public Uf Uf { get; set; }\n    }\n}\n```\n\nAnd, create another directory called 'Repository' and two classes files with the following contents:\n\n`IRepositoryBase.cs`\n```csharp\nusing AspNetCoreDapperMySql.Models;\nusing System.Collections.Generic;\n\nnamespace AspNetCoreDapperMySql.Repository\n{\n    internal interface IRepositoryBase\n    {\n        List\u003cCidade\u003e SearchCidades(string nome);\n\n        List\u003cUf\u003e SearchUfs(string nome);\n\n        List\u003cPais\u003e SearchPaises(string nome);\n    }\n}\n```\n\n`RepositoryBase.cs`\n```csharp\nusing AspNetCoreDapperMySql.Code;\nusing AspNetCoreDapperMySql.Models;\nusing Dapper;\nusing Microsoft.Extensions.Options;\nusing MySql.Data.MySqlClient;\nusing System.Collections.Generic;\nusing System.Data;\nusing System.Data.SqlClient;\nusing System.Linq;\n\nnamespace AspNetCoreDapperMySql.Repository\n{\n    public class RepositoryBase : IRepositoryBase\n    {\n        private readonly IDbConnection _db;\n\n        public RepositoryBase(IOptions\u003cConnectionStringList\u003e connectionStrings)\n        {\n            _db = new MySqlConnection(connectionStrings.Value.ConnectionString1);\n        }\n\n        public void Dispose()\n        {\n            _db.Close();\n        }\n\n        public List\u003cCidade\u003e SearchCidades(string nome)\n        {\n            nome = \"Juiz de Fora\";\n\n            if (string.IsNullOrEmpty(nome))\n                return _db.Query\u003cCidade\u003e(\"SELECT * FROM GLB_Cidade ORDER BY Nome ASC LIMIT 10\").ToList();\n\n            nome = nome.Trim();\n\n            return _db.Query\u003cCidade\u003e(\"SELECT * FROM GLB_Cidade WHERE Nome LIKE @Nome ORDER BY Nome ASC LIMIT 10\", new { Nome = string.Format(\"%{0}%\", nome) }).ToList();\n        }\n\n        public List\u003cUf\u003e SearchUfs(string nome)\n        {\n            if (string.IsNullOrEmpty(nome))\n                return _db.Query\u003cUf\u003e(\"SELECT * FROM GLB_UF ORDER BY Nome ASC LIMIT 10\").ToList();\n\n            nome = nome.Trim();\n\n            return _db.Query\u003cUf\u003e(\"SELECT * FROM GLB_UF WHERE Nome LIKE @Nome ORDER BY Nome ASC LIMIT 10\", new { Nome = string.Format(\"%{0}%\", nome) }).ToList();\n        }\n\n        public List\u003cPais\u003e SearchPaises(string nome)\n        {\n            if (string.IsNullOrEmpty(nome))\n                return _db.Query\u003cPais\u003e(\"SELECT * FROM GLB_Pais ORDER BY Nome ASC LIMIT 10\").ToList();\n\n            nome = nome.Trim();\n\n            return _db.Query\u003cPais\u003e(\"SELECT * FROM GLB_Pais WHERE Nome LIKE @Nome ORDER BY Nome ASC LIMIT 10\", new { Nome = string.Format(\"%{0}%\", nome) }).ToList();\n        }\n    }\n}\n```\n\n\nNuget packages applied\n----------------------\n\n- [Dapper](https://www.nuget.org/packages/Dapper)\n- [Dapper.Contrib](https://www.nuget.org/packages/Dapper.Contrib/)\n- [MySqlConnector](https://www.nuget.org/packages/MySqlConnector/)\n\n\nLicense\n-------\n\nThis example application is [MIT Licensed](https://github.com/anzolin/AspNetCoreDapperMySql/blob/master/LICENSE).\n\n\nAbout the author\n----------------\n\nHello everyone, my name is Diego Anzolin Ferreira. I'm a .NET developer from Brazil. I hope you will enjoy this simple example application as much as I enjoy developing it. If you have any problems, you can post a [GitHub issue](https://github.com/anzolin/AspNetCoreDapperMySql/issues). You can reach me out at diego@anzolin.com.br.\n\n\n## Donate\n  \nWant to help me keep creating open source projects, make a donation:\n\n[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg?style=for-the-badge)](https://www.paypal.com/donate?business=DN2VPNW42RTXY\u0026no_recurring=0\u0026currency_code=BRL) [![Donate](https://img.shields.io/badge/-buy_me_a%C2%A0coffee-gray?logo=buy-me-a-coffee\u0026style=for-the-badge)](https://www.buymeacoffee.com/anzolin)\n\nThank you!\n\n\n\n\u003c!-- MARKDOWN LINKS \u0026 IMAGES --\u003e\n\u003c!-- https://www.markdownguide.org/basic-syntax/#reference-style-links --\u003e\n[contributors-shield]: https://img.shields.io/github/contributors/anzolin/AspNetCoreDapperMySql.svg?style=for-the-badge\n[contributors-url]: https://github.com/anzolin/AspNetCoreDapperMySql/graphs/contributors\n[forks-shield]: https://img.shields.io/github/forks/anzolin/AspNetCoreDapperMySql.svg?style=for-the-badge\n[forks-url]: https://github.com/anzolin/AspNetCoreDapperMySql/network/members\n[stars-shield]: https://img.shields.io/github/stars/anzolin/AspNetCoreDapperMySql.svg?style=for-the-badge\n[stars-url]: https://github.com/anzolin/AspNetCoreDapperMySql/stargazers\n[issues-shield]: https://img.shields.io/github/issues/anzolin/AspNetCoreDapperMySql.svg?style=for-the-badge\n[issues-url]: https://github.com/anzolin/AspNetCoreDapperMySql/issues\n[license-shield]: https://img.shields.io/github/license/anzolin/AspNetCoreDapperMySql.svg?style=for-the-badge\n[license-url]: https://github.com/anzolin/AspNetCoreDapperMySql/blob/master/LICENSE.txt\n[linkedin-shield]: https://img.shields.io/badge/-LinkedIn-black.svg?style=for-the-badge\u0026logo=linkedin\u0026colorB=555\n[linkedin-url]: https://www.linkedin.com/in/diego-anzolin/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanzolin%2Faspnetcoredappermysql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanzolin%2Faspnetcoredappermysql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanzolin%2Faspnetcoredappermysql/lists"}