{"id":21477564,"url":"https://github.com/adamfoneil/dapper.cx","last_synced_at":"2025-07-15T10:33:32.414Z","repository":{"id":65413830,"uuid":"222140789","full_name":"adamfoneil/Dapper.CX","owner":"adamfoneil","description":"A Crud library based on Dapper","archived":false,"fork":false,"pushed_at":"2024-01-24T00:55:29.000Z","size":1229,"stargazers_count":8,"open_issues_count":9,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-11-14T19:52:04.623Z","etag":null,"topics":["crud-generator","crud-operation","crud-operations","dapper","dapper-extensions"],"latest_commit_sha":null,"homepage":"","language":"C#","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/adamfoneil.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,"publiccode":null,"codemeta":null}},"created_at":"2019-11-16T18:16:48.000Z","updated_at":"2024-01-24T00:55:12.000Z","dependencies_parsed_at":"2024-06-19T01:54:47.367Z","dependency_job_id":null,"html_url":"https://github.com/adamfoneil/Dapper.CX","commit_stats":null,"previous_names":["adamosoftware/dapper.cx"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adamfoneil%2FDapper.CX","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adamfoneil%2FDapper.CX/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adamfoneil%2FDapper.CX/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adamfoneil%2FDapper.CX/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adamfoneil","download_url":"https://codeload.github.com/adamfoneil/Dapper.CX/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226033242,"owners_count":17563126,"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":["crud-generator","crud-operation","crud-operations","dapper","dapper-extensions"],"created_at":"2024-11-23T11:14:17.568Z","updated_at":"2024-11-23T11:14:18.131Z","avatar_url":"https://github.com/adamfoneil.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build status](https://ci.appveyor.com/api/projects/status/90etxh1r0aycv1j9?svg=true)](https://ci.appveyor.com/project/adamosoftware/dapper-cx) \n[![Nuget](https://img.shields.io/nuget/v/Dapper.CX.SqlServer?label=SqlServer)](https://www.nuget.org/packages/Dapper.CX.SqlServer/)\n[![Nuget](https://img.shields.io/nuget/v/Dapper.CX.SqlServer.AspNetCore?label=AspNetCore)](https://www.nuget.org/packages/Dapper.CX.SqlServer.AspNetCore/)\n\n**Note:** I'm no longer updating this. Please see [Dapper.Repository](https://github.com/adamfoneil/Dapper.Repository).\n\nDapper.CX is a CRUD library for SQL Server made with Dapper. It works with POCO classes, where the only model class requirement is that they have a property called `Id` or an [Identity](https://github.com/adamosoftware/DbSchema.Attributes/blob/master/DbSchema.Attributes/Attributes/IdentityAttribute.cs) attribute on the class that indicates what its identity property is. `int` and `long` identity types are supported. You can use Dapper.CX in two ways:\n\n- as an injected service, [learn more](https://github.com/adamfoneil/Dapper.CX/wiki/Using-Dapper.CX-with-Dependency-Injection). This is intended for .NET Core apps to use dependency injection along with user profile integration.\n- as `IDbConnection` extension methods, [learn more](https://github.com/adamfoneil/Dapper.CX/wiki/Using-Dapper.CX-Extension-Methods). This is simpler to use than the service, but is not as elegant from a dependency standpoint.\n\nWiki links: [Why Dapper.CX?](https://github.com/adamosoftware/Dapper.CX/wiki), [Reference](https://github.com/adamosoftware/Dapper.CX/wiki/Crud-method-reference). Note that Dapper.CX doesn't create tables. Please see my [ModelSync](https://github.com/adamosoftware/ModelSync) project for info on that.\n\nPlease see my [BlazorAO](https://github.com/adamfoneil/BlazorAO) project to see Dapper.CX in action. If you're not familiar with Dapper, I have a [PowerPoint](https://1drv.ms/v/s!AvguHRnyJtWMmugqfwkiWSa0ZWlqUg?e=8rSid8) **Why I Use Dapper for .NET Data Access** that's an intro and also shows where Dapper.CX builds upon it.\n\n## In a Nutshell\nWhen using the injected service, you'd write CRUD code that looks like this. This example assumes a fictional `Employee` model class. There are several advantages of using the injected service. One, it integrates nicely with the authenticated user to check permissions or perform audit and change tracking. Two, you can omit the `using` block that you otherwise need when interacting with a connection. Three, there are some handy overloads that bundle exception handling and more. Here's [how to implement the injected service](https://github.com/adamfoneil/Dapper.CX/wiki/Using-Dapper.CX-with-Dependency-Injection) along with a CRUD [method reference](https://github.com/adamfoneil/Dapper.CX/wiki/SqlCrudService-reference).\n\n```csharp\npublic EmployeesModel(DapperCX\u003cint\u003e data)\n{\n\tData = data;\n}\n\npublic DapperCX\u003cint\u003e Data { get; }\n\npublic Employee ViewRecord { get; set; }\n\npublic async Task OnGetAsync(int id)\n{\n    ViewRecord = await Data.GetAsync\u003cEmployee\u003e(id);\n}\n\npublic async Task\u003cIActionResult\u003e OnPostSaveAsync(Employee employee)\n{\n    await Data.SaveAsync(employee);\n    return Redirect(\"/Employees\");\n}\n\npublic async Task\u003cIActionResult\u003e OnPostDeleteAsync(int id)\n{\n    await Data.DeleteAsync\u003cEmployee\u003e(id);\n    return Redirect(\"/Employees\");\n}\n```\n\nWhen using the extension methods, it's almost the same thing, but you must open a database connection first. This example assumes a fictional `GetConnection` method that opens a SQL Server connection.\n\n```csharp\npublic Employee ViewRecord { get; set; }\n\npublic async Task OnGetAsync(int id)\n{\n    using (var cn = GetConnection())\n    {\n        ViewRecord = await cn.GetAsync\u003cEmployee\u003e(id);\n    }    \n}\n\npublic async Task\u003cIActionResult\u003e OnPostSaveAsync(Employee employee)\n{\n    using (var cn = GetConnection())\n    {\n        await cn.SaveAsync(employee);\n        return Redirect(\"/Employees\");\n    }\n}\n\npublic async Task\u003cIActionResult\u003e OnPostDeleteAsync(int id)\n{\n    using (var cn = GetConnection())\n    {\n        await cn.DeleteAsync\u003cEmployee\u003e(id);\n        return Redirect(\"/Employees\");\n    }\n}\n```\n\n## Customizing behaviors with interfaces\nThere's a lot of functionality you can opt into by implementing interfaces on your model classes from the [AO.Models](https://github.com/adamfoneil/Models) project. See [Extending Dapper.CX with Interfaces](https://github.com/adamfoneil/Dapper.CX/wiki/Extending-Dapper.CX-with-Opt-in-Interfaces). Available interfaces are [here](https://github.com/adamfoneil/Models/tree/master/Models/Interfaces).\n\n## And one other thing...\nIn addition to the more common strong-typed CRUD operations, Dapper.CX also offers a [SqlCmdDictionary](https://github.com/adamosoftware/Dapper.CX/wiki/Using-SqlCmdDictionary) feature that gives you a clean way to build INSERT and UPDATE statements dynamically.\n\n## One other thing...\nIf you need a `Dictionary`-like object to persist in a database, you can implement the abstract class [DbDictionary](https://github.com/adamfoneil/Dapper.CX/blob/master/Dapper.CX.Base/Abstract/DbDictionary.cs). Use this to store any object with a key, using these [supported key types](https://github.com/adamfoneil/Dapper.CX/blob/master/Dapper.CX.Base/Abstract/DbDictionary.cs#L29-L35). This can save you the effort of adding a single-use dedicated model class for a more generic storage need. Note that, unlike a `Dictinoary\u003cTKey, TValue\u003e`, you can use different `TValue`s with different keys, so this is very flexible and still type-safe. The abstract methods [Serialize](https://github.com/adamfoneil/Dapper.CX/blob/master/Dapper.CX.Base/Abstract/DbDictionary.cs#L65) and [Deserialize](https://github.com/adamfoneil/Dapper.CX/blob/master/Dapper.CX.Base/Abstract/DbDictionary.cs#L63) let you provide your Json serialization. See the [integration test](https://github.com/adamfoneil/Dapper.CX/blob/master/Tests.Base/SqlIntegration.cs#L116) to see in action, along with the [sample implementation](https://github.com/adamfoneil/Dapper.CX/blob/master/Tests.Base/SampleDbDictionary.cs).\n\n---\nPlease see also [Dapper.QX](https://github.com/adamosoftware/Dapper.QX), Dapper.CX's companion library.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadamfoneil%2Fdapper.cx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadamfoneil%2Fdapper.cx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadamfoneil%2Fdapper.cx/lists"}