{"id":13431318,"url":"https://github.com/henkmollema/Dapper-FluentMap","last_synced_at":"2025-03-16T11:31:27.105Z","repository":{"id":16354736,"uuid":"19104735","full_name":"henkmollema/Dapper-FluentMap","owner":"henkmollema","description":"Provides a simple API to fluently map POCO properties to database columns when using Dapper.","archived":true,"fork":false,"pushed_at":"2023-04-19T13:48:03.000Z","size":2696,"stargazers_count":431,"open_issues_count":0,"forks_count":90,"subscribers_count":32,"default_branch":"master","last_synced_at":"2025-02-23T09:05:35.161Z","etag":null,"topics":["c-sharp","dapper","poco-properties"],"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/henkmollema.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}},"created_at":"2014-04-24T10:33:12.000Z","updated_at":"2025-01-16T22:36:37.000Z","dependencies_parsed_at":"2024-01-28T20:07:20.034Z","dependency_job_id":"80f31921-e141-4d4f-abe6-2f6426d24c83","html_url":"https://github.com/henkmollema/Dapper-FluentMap","commit_stats":{"total_commits":175,"total_committers":12,"mean_commits":"14.583333333333334","dds":0.1657142857142857,"last_synced_commit":"66a97677a27706fe0d4d07f6e25be9c2ef4b765e"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/henkmollema%2FDapper-FluentMap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/henkmollema%2FDapper-FluentMap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/henkmollema%2FDapper-FluentMap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/henkmollema%2FDapper-FluentMap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/henkmollema","download_url":"https://codeload.github.com/henkmollema/Dapper-FluentMap/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243862871,"owners_count":20360230,"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":["c-sharp","dapper","poco-properties"],"created_at":"2024-07-31T02:01:02.197Z","updated_at":"2025-03-16T11:31:26.676Z","avatar_url":"https://github.com/henkmollema.png","language":"C#","readme":"## 📦 Archived\nThis repository is archived as I'm not using this library myself anymore and have no time maintaining it. Thanks for using it.\n\n\u003chr\u003e\n\n\n# Dapper.FluentMap\nProvides a simple API to fluently map POCO properties to database columns when using Dapper.\n\n\u003chr\u003e\n\n| Windows | Linux/OSX | NuGet |\n| --- | --- | --- |\n| [![Windows Build status](https://ci.appveyor.com/api/projects/status/x6grw3cjuyud9c76?svg=true)](https://ci.appveyor.com/project/henkmollema/dapper-fluentmap) | [![Linux Build Status](https://travis-ci.org/henkmollema/Dapper-FluentMap.svg?branch=master)](https://travis-ci.org/henkmollema/Dapper-FluentMap) | [![NuGet Version](http://img.shields.io/nuget/v/Dapper.FluentMap.svg)](https://www.nuget.org/packages/Dapper.FluentMap/ \"NuGet version\") |\n\n### Introduction\n\nThis [Dapper](https://github.com/StackExchange/dapper-dot-net) extension allows you to fluently configure the mapping between POCO properties and database columns. This keeps your POCO's clean of mapping attributes. The functionality is similar to [Entity Framework Fluent API](http://msdn.microsoft.com/nl-nl/data/jj591617.aspx). If you have any questions, suggestions or bugs, please don't hesitate to [contact me](mailto:henkmollema@gmail.com) or create an issue.\n\n\u003chr\u003e\n\n### Download\n[![Download Dapper.FluentMap on NuGet](http://i.imgur.com/Rs483do.png \"Download Dapper.FluentMap on NuGet\")](https://www.nuget.org/packages/Dapper.FluentMap)\n\n\u003chr\u003e\n\n### Usage\n#### Manual mapping\nYou can map property names manually using the [`EntityMap\u003cTEntity\u003e`](https://github.com/henkmollema/Dapper-FluentMap/blob/master/src/Dapper.FluentMap/Mapping/EntityMap.cs) class. When creating a derived class, the constructor gives you access to the `Map` method, allowing you to specify to which database column name a certain property of `TEntity` should map to.\n```csharp\npublic class ProductMap : EntityMap\u003cProduct\u003e\n{\n    public ProductMap()\n    {\n        // Map property 'Name' to column 'strName'.\n        Map(p =\u003e p.Name)\n            .ToColumn(\"strName\");\n\n        // Ignore the 'LastModified' property when mapping.\n        Map(p =\u003e p.LastModified)\n            .Ignore();\n    }\n}\n```\n\nColumn names are mapped case sensitive by default. You can change this by specifying the `caseSensitive` parameter in the `ToColumn()` method: `Map(p =\u003e p.Name).ToColumn(\"strName\", caseSensitive: false)`.\n\n**Initialization:**\n```csharp\nFluentMapper.Initialize(config =\u003e\n    {\n       config.AddMap(new ProductMap());\n    });\n```\n\n#### Convention based mapping\nWhen you have a lot of entity types, creating manual mapping classes can become plumbing. If your column names adhere to some kind of naming convention, you might be better off by configuring a mapping convention.\n\nYou can create a convention by creating a class which derives from the [`Convention`](https://github.com/henkmollema/Dapper-FluentMap/blob/master/src/Dapper.FluentMap/Conventions/Convention.cs) class. In the contructor you can configure the property conventions:\n```csharp\npublic class TypePrefixConvention : Convention\n{\n    public TypePrefixConvention()\n    {\n        // Map all properties of type int and with the name 'id' to column 'autID'.\n        Properties\u003cint\u003e()\n            .Where(c =\u003e c.Name.ToLower() == \"id\")\n            .Configure(c =\u003e c.HasColumnName(\"autID\"));\n\n        // Prefix all properties of type string with 'str' when mapping to column names.\n        Properties\u003cstring\u003e()\n            .Configure(c =\u003e c.HasPrefix(\"str\"));\n\n        // Prefix all properties of type int with 'int' when mapping to column names.\n        Properties\u003cint\u003e()\n            .Configure(c =\u003e c.HasPrefix(\"int\"));\n    }\n}\n```\n\nWhen initializing Dapper.FluentMap with conventions, the entities on which a convention applies must be configured. You can choose to either configure the entities explicitly or use assembly scanning.\n\n```csharp\nFluentMapper.Initialize(config =\u003e\n    {\n        // Configure entities explicitly.\n        config.AddConvention\u003cTypePrefixConvention\u003e()\n              .ForEntity\u003cProduct\u003e()\n              .ForEntity\u003cOrder\u003e;\n\n        // Configure all entities in a certain assembly with an optional namespaces filter.\n        config.AddConvention\u003cTypePrefixConvention\u003e()\n              .ForEntitiesInAssembly(typeof(Product).Assembly, \"App.Domain.Model\");\n\n        // Configure all entities in the current assembly with an optional namespaces filter.\n        config.AddConvention\u003cTypePrefixConvention\u003e()\n              .ForEntitiesInCurrentAssembly(\"App.Domain.Model.Catalog\", \"App.Domain.Model.Order\");\n    });\n```\n\n##### Transformations\nThe convention API allows you to configure transformation of property names to database column names. An implementation would look like this:\n```csharp\npublic class PropertyTransformConvention : Convention\n{\n    public PropertyTransformConvention()\n    {\n        Properties()\n            .Configure(c =\u003e c.Transform(s =\u003e Regex.Replace(input: s, pattern: \"([A-Z])([A-Z][a-z])|([a-z0-9])([A-Z])\", replacement: \"$1$3_$2$4\")));\n    }\n}\n```\n\nThis configuration will map camel case property names to underscore seperated database column names (`UrlOptimizedName` -\u003e `Url_Optimized_Name`).\n\n\u003chr\u003e\n\n### [Dommel](https://github.com/henkmollema/Dommel)\nDommel contains a set of extensions methods providing easy CRUD operations using Dapper. One of the goals was to provide extension points for resolving table and column names. [Dapper.FluentMap.Dommel](https://github.com/henkmollema/Dapper-FluentMap/tree/master/src/Dapper.FluentMap.Dommel) implements certain interfaces of Dommel and uses the configured mapping. It also provides more mapping functionality.\n\n#### [`PM\u003e Install-Package Dapper.FluentMap.Dommel`](https://www.nuget.org/packages/Dapper.FluentMap.Dommel)\n\n#### Usage\n##### `DommelEntityMap\u003cTEntity\u003e`\nThis class derives from `EntityMap\u003cTEntity\u003e` and allows you to map an entity to a database table using the `ToTable()` method:\n\n```csharp\npublic class ProductMap : DommelEntityMap\u003cTEntity\u003e\n{\n    public ProductMap()\n    {\n        ToTable(\"tblProduct\");\n\n        // ...\n    }\n}\n```\n\n##### `DommelPropertyMap\u003cTEntity\u003e`\nThis class derives `PropertyMap\u003cTEntity\u003e` and allows you to specify the key property of an entity using the `IsKey` method:\n\n```csharp\npublic class ProductMap : DommelEntityMap\u003cTEntity\u003e\n{\n    public ProductMap()\n    {\n        Map(p =\u003e p.Id).IsKey();\n    }\n}\n```\n\nYou can configure Dapper.FluentMap.Dommel in the `FluentMapper.Initialize()` method:\n\n```csharp\nFluentMapper.Initialize(config =\u003e\n    {\n        config.AddMap(new ProductMap());\n        config.ForDommel();\n    });\n```\n","funding_links":[],"categories":["Frameworks, Libraries and Tools","框架, 库和工具","Libraries","ORM"],"sub_categories":["ORM","对象关系映射ORM","ORM and Micro-ORM"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhenkmollema%2FDapper-FluentMap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhenkmollema%2FDapper-FluentMap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhenkmollema%2FDapper-FluentMap/lists"}