{"id":13595029,"url":"https://github.com/yorek/dapper-samples","last_synced_at":"2025-08-22T18:12:44.278Z","repository":{"id":27286447,"uuid":"111474610","full_name":"yorek/dapper-samples","owner":"yorek","description":"Tutorial samples that shows how to use Dapper .NET","archived":false,"fork":false,"pushed_at":"2022-12-08T00:58:57.000Z","size":1339,"stargazers_count":177,"open_issues_count":1,"forks_count":26,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-12-10T05:42:57.331Z","etag":null,"topics":["dapper","donet-core","dotnet","micro-orm","orm"],"latest_commit_sha":null,"homepage":"https://medium.com/dapper-net","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yorek.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}},"created_at":"2017-11-20T23:35:48.000Z","updated_at":"2024-11-08T21:15:57.000Z","dependencies_parsed_at":"2023-01-14T06:23:36.532Z","dependency_job_id":null,"html_url":"https://github.com/yorek/dapper-samples","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yorek%2Fdapper-samples","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yorek%2Fdapper-samples/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yorek%2Fdapper-samples/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yorek%2Fdapper-samples/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yorek","download_url":"https://codeload.github.com/yorek/dapper-samples/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230394228,"owners_count":18218707,"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":["dapper","donet-core","dotnet","micro-orm","orm"],"created_at":"2024-08-01T16:01:42.673Z","updated_at":"2024-12-19T07:07:18.506Z","avatar_url":"https://github.com/yorek.png","language":"C#","readme":"# Dapper .NET Samples\n## Samples that shows how to use Dapper .NET.\n\nThese are the samples mentioned in the [Dapper .Net](https://github.com/StackExchange/Dapper) publication on Medium:\n\n[https://medium.com/dapper-net](https://medium.com/dapper-net)\n\nHere's the list of samples and the related article:\n\n 1. [Getting Started with Dapper .NET](https://medium.com/dapper-net/get-started-with-dapper-net-591592c335aa)\n 2. [Multiple Executions](https://medium.com/dapper-net/multiple-executions-56c410e9f8dd)\n 3. [Multiple Resultsets](https://medium.com/dapper-net/handling-multiple-resultsets-4b108a8c5172)\n 4. [Multiple Mapping](https://medium.com/dapper-net/multiple-mapping-d36c637d14fa)\n 5. [SQL Server Features](https://medium.com/dapper-net/sql-server-specific-features-2773d894a6ae)\n 6. [Custom Mapping](https://medium.com/dapper-net/custom-columns-mapping-1cd45dfd51d6)\n 7. [Custom Handling](https://medium.com/dapper-net/custom-type-handling-4b447b97c620)\n 8. [One-To-Many Relationships](https://medium.com/dapper-net/one-to-many-mapping-with-dapper-55ae6a65cfd4)\n 9. [Complex Custom Handling](https://medium.com/dapper-net/one-to-many-mapping-with-dapper-55ae6a65cfd4)\n\nPlease note that the \"One-To-Many Relatioships\" and \"Complex Custom Handling\" points to the same articles since both topics are discussed there as they are strictly related to each other.\n\n## Running The Samples\n\nTo run the \"Basic Samples\", related to the first article \"Getting Started with Dapper .NET\", just run\n\n```dotnet run -f net5.0```\n\nfrom\n\n```Dapper.Samples.Basics```\n\nfolder. To run advanced samples you have to move into \n\n```Dapper.Samples.Advanced```\n\nand then from here you can just run\n\n```dotnet run -f net5.0```\n\nto run ALL samples or \n\n```dotnet run -f net5.0 \"Sample Name\"```\n\nto run that specific sample. Eg:\n\n```dotnet run -f net5.0 \"Multiple Executions\"```\n\nto run only the \"Multiple Execution\" sample.\n\nTo have a list of all advanced samples available run:\n\n```dotnet run -f net5.0 -help```\n\n## Notes\n\n### .NET Version\n\nSamples are done using [.NET 5.0](https://dotnet.microsoft.com/download/dotnet/5.0), and [.NET Framework 4.8](https://www.microsoft.com/net/download/windows): make sure you have them installed it on your machine\n\nThe project supports multiple targets:\n\n* net5.0\n* netcoreapp3.1\n* net48\n\nTo execute the application targeting one specific framework, just use the `-f` option when running the console app:\n\n```dotnet run -f net5.0```\n\nmore info on the `-f` option here:\n\n[dotnet run](https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-run)\n\nIf you are looking for samples supporting older version, take a look at the previous releases as they support also:\n\n* .NET Framework 4.5.2\n* .NET Core 2.0\n* Dapper 1.50\n\n### SQL Server\n\nSamples also use SQL Server as database server. If you don't have a Windows machine, you can use the Docker version: [SQL Server 2017](https://www.microsoft.com/en-us/sql-server/sql-server-2017). \nSQL Server database file is attached automatically using the `LocalDB/MSSQLServer` instance. If you prefer to use a non-local instance, make sure you change the connection string accordingly, and attach the database file to your instance.\n\n\n### OPENJSON and 2K limit\n\nIn Azure SQL and SQL Server, when JSON is returned as part of a SELECT ... FOR JSON, if the resulting JSON is bigger than 2K, it will be chunked and thus it must be put back together on the client. Using SQL Server Management Studio you will not see any of this as it automatically do this for you, but if you using .NET you have to do it yourself as described here: [User FOR JSON output in a C# client app](https://docs.microsoft.com/en-us/sql/relational-databases/json/use-for-json-output-in-sql-server-and-in-client-apps-sql-server). This is actually true for other languages and not only for C#.\nA bit more detail on this behavior here: [SQL Server JSON result separated in multiple rows](https://stackoverflow.com/questions/41880611/sql-server-json-result-separated-in-multiple-rows/41915103#41915103).\n\nThe samples have been updated to show how to properly manage this behavior, as also described in this post by MVP Hasan Savran: [JSON Challenges for DEVS in SQL Server](https://h-savran.blogspot.com/2020/04/challenges-with-returning-data-as-json.html). \n\nThe \"trick\" is to wrap FOR JSON in another SELECT or assign it to a variable:\n\n```sql\nSELECT (\n\tSELECT\t\n\t\tu.Id,\n\t\tu.FirstName,\n\t\tu.LastName,\n\t\tu.EMailAddress AS 'EmailAddress',\n\t\t(SELECT JSON_QUERY(REPLACE(REPLACE((SELECT [Tag] FROM dbo.[UserTags] t WHERE t.UserId = u.Id FOR JSON PATH), '{\"Tag\":', ''), '}', ''))) AS Tags,\n\t\tJSON_QUERY((SELECT r.[value] as [RoleName] FROM dbo.[Users] ur CROSS APPLY STRING_SPLIT(Roles, ',') AS r WHERE ur.Id = u.Id FOR JSON AUTO)) AS Roles,\n\t\tu.Notes,\n\t\tc.Id AS 'Company.Id',\n\t\tc.CompanyName AS 'Company.CompanyName',\n\t\tc.Street AS 'Company.Address.Street',\n\t\tc.City AS 'Company.Address.City',\n\t\tc.[State] AS 'Company.Address.State',\n\t\tc.Country AS 'Company.Address.Country',\n\t\tJSON_QUERY(u.CustomData, '$.Preferences') AS Preferences\n\tFROM\n\t\tdbo.[Users] u\n\tLEFT JOIN\n\t\tdbo.[Companies] c ON u.CompanyId = c.Id\n\tWHERE\n\t\tu.id = @id\n\tFOR JSON PATH, WITHOUT_ARRAY_WRAPPER\n) as [object]\n```\n\n## Learn More\n\nIf you want to learn more on how to create modern application with SQL Server and Azure SQL, the following book is for you:\n\n[![Practical Azure SQL Database for Modern Developers](./book-cover.jpg)](https://www.apress.com/it/book/9781484263693)\n\n### About This Book\n\nHere is the expert-level, insider guidance you need on using Azure SQL Database as your back-end data store. This book highlights best practices in everything ranging from full-stack projects to mobile applications to critical, back-end APIs. The book provides instruction on accessing your data from any language and platform. And you learn how to push processing-intensive work into the database engine to be near the data and avoid undue networking traffic. Azure SQL is explained from a developer's point of view, helping you master its feature set and create applications that perform well and delight users.\n\nCore to the book is showing you how Azure SQL Database provides relational and post-relational support so that any workload can be managed with easy accessibility from any platform and any language. You will learn about features ranging from lock-free tables to columnstore indexes, and about support for data formats ranging from JSON and key-values to the nodes and edges in the graph database paradigm. Reading this book prepares you to deal with almost all data management challenges, allowing you to create lean and specialized solutions having the elasticity and scalability that are needed in the modern world. \n\n### What You Will Learn\n\nMaster Azure SQL Database in your development projects from design to the CI/CD pipeline\nAccess your data from any programming language and platform\nCombine key-value, JSON, and relational data in the same database\nPush data-intensive compute work into the database for improved efficiency\nDelight your customers by detecting and improving poorly performing queries\nEnhance performance through features such as columnstore indexes and lock-free tables\nBuild confidence in your mastery of Azure SQL Database's feature set\n\n\n### Who This Book Is For\nDevelopers of applications and APIs that benefit from cloud database support, developers who wish to master their tools (including Azure SQL Database, and those who want their applications to be known for speedy performance and the elegance of their code","funding_links":[],"categories":["dotnet","C#","C\\#"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyorek%2Fdapper-samples","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyorek%2Fdapper-samples","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyorek%2Fdapper-samples/lists"}