{"id":18557000,"url":"https://github.com/dapperlib/dapper.contrib","last_synced_at":"2025-05-16T15:07:20.277Z","repository":{"id":38843387,"uuid":"365612559","full_name":"DapperLib/Dapper.Contrib","owner":"DapperLib","description":"Dapper community contributions - additional extensions for Dapper","archived":false,"fork":false,"pushed_at":"2024-05-27T09:38:20.000Z","size":47990,"stargazers_count":284,"open_issues_count":162,"forks_count":105,"subscribers_count":11,"default_branch":"main","last_synced_at":"2025-05-13T17:45:39.570Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DapperLib.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"License.txt","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":"2021-05-08T21:15:24.000Z","updated_at":"2025-05-08T22:39:55.000Z","dependencies_parsed_at":"2024-11-06T21:37:28.651Z","dependency_job_id":"aeb036db-e2bc-4e26-89b7-06da72afc887","html_url":"https://github.com/DapperLib/Dapper.Contrib","commit_stats":{"total_commits":1161,"total_committers":205,"mean_commits":5.663414634146341,"dds":0.7364341085271318,"last_synced_commit":"cf24f6bdc577b1e071c3764ddfb2cf3382531405"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DapperLib%2FDapper.Contrib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DapperLib%2FDapper.Contrib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DapperLib%2FDapper.Contrib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DapperLib%2FDapper.Contrib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DapperLib","download_url":"https://codeload.github.com/DapperLib/Dapper.Contrib/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254553959,"owners_count":22090417,"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":[],"created_at":"2024-11-06T21:34:09.943Z","updated_at":"2025-05-16T15:07:20.254Z","avatar_url":"https://github.com/DapperLib.png","language":"C#","readme":"Dapper.Contrib - a simple object mapper for .Net\n========================================\n[![Build status](https://ci.appveyor.com/api/projects/status/1w448i6nfxd14w75?svg=true)](https://ci.appveyor.com/project/StackExchange/dapper-contrib)\n\nRelease Notes\n-------------\nLocated at [dapperlib.github.io/Dapper.Contrib](https://dapperlib.github.io/Dapper.Contrib/)\n\nPackages\n--------\n\nMyGet Pre-release feed: https://www.myget.org/gallery/dapper\n\n| Package | NuGet Stable | NuGet Pre-release | Downloads | MyGet |\n| ------- | ------------ | ----------------- | --------- | ----- |\n| [Dapper.Contrib](https://www.nuget.org/packages/Dapper.Contrib/) | [![Dapper.Contrib](https://img.shields.io/nuget/v/Dapper.Contrib.svg)](https://www.nuget.org/packages/Dapper.Contrib/) | [![Dapper.Contrib](https://img.shields.io/nuget/vpre/Dapper.Contrib.svg)](https://www.nuget.org/packages/Dapper.Contrib/) | [![Dapper.Contrib](https://img.shields.io/nuget/dt/Dapper.Contrib.svg)](https://www.nuget.org/packages/Dapper.Contrib/) | [![Dapper.Contrib MyGet](https://img.shields.io/myget/dapper/vpre/Dapper.Contrib.svg)](https://www.myget.org/feed/dapper/package/nuget/Dapper.Contrib) |\n\nFeatures\n--------\n\nDapper.Contrib contains a number of helper methods for inserting, getting,\nupdating and deleting records.\n\nThe full list of extension methods in Dapper.Contrib right now are:\n\n```csharp\nT Get\u003cT\u003e(id);\nIEnumerable\u003cT\u003e GetAll\u003cT\u003e();\nint Insert\u003cT\u003e(T obj);\nint Insert\u003cT\u003e(Enumerable\u003cT\u003e list);\nbool Update\u003cT\u003e(T obj);\nbool Update\u003cT\u003e(Enumerable\u003cT\u003e list);\nbool Delete\u003cT\u003e(T obj);\nbool Delete\u003cT\u003e(Enumerable\u003cT\u003e list);\nbool DeleteAll\u003cT\u003e();\n```\n\nFor these extensions to work, the entity in question _MUST_ have a\nkey property. Dapper will automatically use a property named \"`id`\" \n(case-insensitive) as the key property, if one is present.\n\n```csharp\npublic class Car\n{\n    public int Id { get; set; } // Works by convention\n    public string Name { get; set; }\n}\n```\n\nIf the entity doesn't follow this convention, decorate \na specific property with a `[Key]` or `[ExplicitKey]` attribute.\n\n```csharp\npublic class User\n{\n    [Key]\n    int TheId { get; set; }\n    string Name { get; set; }\n    int Age { get; set; }\n}\n```\n\n`[Key]` should be used for database-generated keys (e.g. autoincrement columns), \nwhile `[ExplicitKey]` should be used for explicit keys generated in code.\n\n`Get` methods\n-------\n\nGet one specific entity based on id\n\n```csharp\nvar car = connection.Get\u003cCar\u003e(1);\n```\n\nor a list of all entities in the table.\n\n```csharp\nvar cars = connection.GetAll\u003cCar\u003e();\n```\n\n`Insert` methods\n-------\n\nInsert one entity\n\n```csharp\nconnection.Insert(new Car { Name = \"Volvo\" });\n```\n\nor a list of entities.\n\n```csharp\nconnection.Insert(cars);\n```\n\n\n\n`Update` methods\n-------\nUpdate one specific entity\n\n```csharp\nconnection.Update(new Car() { Id = 1, Name = \"Saab\" });\n```\n\nor update a list of entities.\n\n```csharp\nconnection.Update(cars);\n```\n\n`Delete` methods\n-------\nDelete an entity by the specified `[Key]` property\n\n```csharp\nconnection.Delete(new Car() { Id = 1 });\n```\n\na list of entities\n\n```csharp\nconnection.Delete(cars);\n```\n\nor _ALL_ entities in the table.\n\n```csharp\nconnection.DeleteAll\u003cCar\u003e();\n```\n\nSpecial Attributes\n----------\nDapper.Contrib makes use of some optional attributes:\n\n* `[Table(\"Tablename\")]` - use another table name instead of the (by default pluralized) name of the class\n\n    ```csharp\n    [Table (\"emps\")]\n    public class Employee\n    {\n        public int Id { get; set; }\n        public string Name { get; set; }\n    }\n    ```\n* `[Key]` - this property represents a database-generated identity/key\n    \n    ```csharp\n    public class Employee\n    {\n        [Key]\n        public int EmployeeId { get; set; }\n        public string Name { get; set; }\n    }\n    ```\n* `[ExplicitKey]` - this property represents an explicit identity/key which is \n  *not* automatically generated by the database \n\n    ```csharp\n    public class Employee\n    {\n        [ExplicitKey]\n        public Guid EmployeeId { get; set; }\n        public string Name { get; set; }\n    }\n    ```\n* `[Write(true/false)]` -  this property is (not) writeable\n* `[Computed]` - this property is computed and should not be part of updates\n\nLimitations and caveats\n-------\n\n### SQLite\n\n`SQLiteConnection` exposes an `Update` event that clashes with the `Update`\nextension provided by Dapper.Contrib. There are 2 ways to deal with this.\n\n1. Call the `Update` method explicitly from `SqlMapperExtensions`\n\n    ```Csharp\n    SqlMapperExtensions.Update(_conn, new Employee { Id = 1, Name = \"Mercedes\" });\n    ```\n2. Make the method signature unique by passing a type parameter to `Update`\n\n    ```Csharp\n    connection.Update\u003cCar\u003e(new Car() { Id = 1, Name = \"Maruti\" });\n    ```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdapperlib%2Fdapper.contrib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdapperlib%2Fdapper.contrib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdapperlib%2Fdapper.contrib/lists"}