{"id":13431354,"url":"https://github.com/nreco/data","last_synced_at":"2025-04-09T23:19:35.062Z","repository":{"id":42350750,"uuid":"63479100","full_name":"nreco/data","owner":"nreco","description":"Fast DB-independent DAL for .NET Core:  abstract queries, SQL commands builder, schema-less data access, POCO mapping (micro-ORM).","archived":false,"fork":false,"pushed_at":"2024-01-17T15:33:38.000Z","size":1165,"stargazers_count":189,"open_issues_count":5,"forks_count":39,"subscribers_count":26,"default_branch":"master","last_synced_at":"2025-04-02T21:09:45.342Z","etag":null,"topics":["crud","csharp","data-access-layer","database","dot-net","dotnetcore","micro-orm","orm","poco","sql-builder","sql-generation"],"latest_commit_sha":null,"homepage":"https://www.nrecosite.com/dalc_net.aspx","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/nreco.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":"2016-07-16T11:05:06.000Z","updated_at":"2025-03-12T18:48:05.000Z","dependencies_parsed_at":"2024-12-18T17:11:29.778Z","dependency_job_id":"7fbf9cc5-4eb0-454f-ab2d-72d0b761c85e","html_url":"https://github.com/nreco/data","commit_stats":{"total_commits":138,"total_committers":5,"mean_commits":27.6,"dds":"0.13043478260869568","last_synced_commit":"6d982b95df8e83cba56e3419cc5830511a8d9737"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nreco%2Fdata","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nreco%2Fdata/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nreco%2Fdata/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nreco%2Fdata/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nreco","download_url":"https://codeload.github.com/nreco/data/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248125851,"owners_count":21051813,"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","csharp","data-access-layer","database","dot-net","dotnetcore","micro-orm","orm","poco","sql-builder","sql-generation"],"created_at":"2024-07-31T02:01:02.435Z","updated_at":"2025-04-09T23:19:35.039Z","avatar_url":"https://github.com/nreco.png","language":"C#","readme":"# NReco.Data\nLightweight high-performance data access components for generating SQL commands, mapping results to strongly typed POCO models or dictionaries, schema-less CRUD-operations with RecordSet. \n\nNuGet | Windows x64 | Ubuntu\n--- | --- | ---\n[![NuGet Release](https://img.shields.io/nuget/v/NReco.Data.svg)](https://www.nuget.org/packages/NReco.Data/) | [![AppVeyor](https://img.shields.io/appveyor/ci/nreco/data/master.svg)](https://ci.appveyor.com/project/nreco/data) | ![Tests](https://github.com/nreco/data/actions/workflows/dotnet-test.yml/badge.svg) \n\n* very fast: NReco.Data shows almost the same performance as Dapper but offers more features\n* abstract DB-independent [Query structure](https://github.com/nreco/data/wiki/Query): no need to compose raw SQL in the code + query can be constructed dynamically (at run-time)\n* automated CRUD commands generation\n* generate several SQL statements into one IDbCommand (batch inserts, updates, selects for multiple recordsets: *DbBatchCommandBuilder*)\n* supports mapping to annotated POCO models (EF Core entity models), allows customized mapping of query result \n* API for schema-less data access (dictionaries, RecordSet, DataTable)\n* can handle results returned by stored procedure, including multiple record sets\n* application-level data views (for complex SQL queries) that accessed like simple read-only tables (DbDataView)\n* parser for compact string query representation: [relex](https://github.com/nreco/data/wiki/Relex) expressions\n* can be used with any existing ADO.NET data provider (SQL Server, PostgreSql, Sqlite, MySql, Oracle etc)\n* supports .NET Framework 4.5+, .NET Core 2.x / 3.x (netstandard2.0)\n\n## Quick reference\nClass | Dependencies | Purpose\n--- | --- | ---\n`DbFactory` | | incapsulates DB-specific functions and conventions \n`DbCommandBuilder` | *IDbFactory* | composes *IDbCommand* and SQL text for SELECT/UPDATE/DELETE/INSERT, handles app-level dataviews\n`DbDataAdapter` | *IDbCommandBuilder*, *IDbConnection* | CRUD operations for model, dictionary, *DataTable* or *[RecordSet](https://github.com/nreco/data/wiki/RecordSet)*: Insert/Update/Delete/Select. Async versions are supported for all methods.\n`Query` | | Represents abstract query to database; used as parameter in *DbCommandBuilder*, *DbDataAdapter*\n`RelexParser` | | Parsers query string expression ([Relex](https://github.com/nreco/data/wiki/Relex)) into *Query* structure\n`RecordSet` | | [RecordSet model](https://github.com/nreco/data/wiki/RecordSet) represents in-memory data records, this is lightweight and efficient replacement for classic *DataTable*/*DataRow*\n`DataReaderResult` | *IDataReader* | reads data from any data reader implementation and efficiently maps it to models, dictionaries, *DataTable* or *RecordSet*\n\nNReco.Data documentation:\n* [Getting started and HowTos](https://github.com/nreco/data/wiki)\n* [Full API Reference](http://www.nrecosite.com/doc/NReco.Data/)\n* something is still not clear? Feel free to [ask a question on StackOverflow](http://stackoverflow.com/questions/ask?tags=nreco,c%23) \n\n## How to use\nGeneric implementation of `DbFactory` can be used with any ADO.NET connector. \n\n**DbFactory initialization for SqlClient**:\n```\nvar dbFactory = new DbFactory(System.Data.SqlClient.SqlClientFactory.Instance) {\n\tLastInsertIdSelectText = \"SELECT @@IDENTITY\" };\n```\n**DbFactory initialization for Mysql**:\n```\nvar dbFactory = new DbFactory(MySql.Data.MySqlClient.MySqlClientFactory.Instance) {\n\tLastInsertIdSelectText = \"SELECT LAST_INSERT_ID()\" };\n```\n**DbFactory initialization for Postgresql**:\n```\nvar dbFactory = new DbFactory(Npgsql.NpgsqlFactory.Instance) {\n\tLastInsertIdSelectText = \"SELECT lastval()\" };\n```\n**DbFactory initialization for Sqlite**:\n```\nvar dbFactory = new DbFactory(Microsoft.Data.Sqlite.SqliteFactory.Instance) {\n\tLastInsertIdSelectText = \"SELECT last_insert_rowid()\" };\n```\n\n**DbCommandBuilder** generates SQL commands by [Query](https://github.com/nreco/data/wiki/Query):\n```\nvar dbCmdBuilder = new DbCommandBuilder(dbFactory);\nvar selectCmd = dbCmdBuilder.GetSelectCommand( \n\tnew Query(\"Employees\", (QField)\"BirthDate\" \u003e new QConst(new DateTime(1960,1,1)) ) );\nvar selectGroupByCmd = dbCmdBuilder.GetSelectCommand( \n\tnew Query(\"Employees\").Select(\"company_id\", new QAggregateField(\"avg_age\", \"AVG\", \"age\") ) );\nvar insertCmd = dbCmdBuilder.GetInsertCommand(\n\t\"Employees\", new { Name = \"John Smith\", BirthDate = new DateTime(1980,1,1) } );\nvar deleteCmd = dbCmdBuilder.GetDeleteCommand(\n\tnew Query(\"Employees\", (QField)\"Name\" == (QConst)\"John Smith\" ) );\n```\n\n**DbDataAdapter** - provides simple API for CRUD-operations:\n```\nvar dbConnection = dbFactory.CreateConnection();\ndbConnection.ConnectionString = \"\u003cdb_connection_string\u003e\";\nvar dbAdapter = new DbDataAdapter(dbConnection, dbCmdBuilder);\n// map select results to POCO models\nvar employeeModelsList = dbAdapter.Select( new Query(\"Employees\") ).ToList\u003cEmployee\u003e();\n// read select result to dictionary\nvar employeeDictionary = dbAdapter.Select( \n    new Query(\"Employees\", (QField)\"EmployeeID\"==(QConst)newEmployee.EmployeeID ).Select(\"FirstName\",\"LastName\") \n  ).ToDictionary();\n// update by dictionary\ndbAdapter.Update( \n\tnew Query(\"Employees\", (QField)\"EmployeeID\"==(QConst)1001 ),\n\tnew Dictionary\u003cstring,object\u003e() {\n\t\t{\"FirstName\", \"Bruce\" },\n\t\t{\"LastName\", \"Wayne\" }\n\t});\n// insert by model\ndbAdapter.Insert( \"Employees\", new { FirstName = \"John\", LastName = \"Smith\" } );  \n```\n**[RecordSet](https://github.com/nreco/data/wiki/RecordSet)** - efficient replacement for DataTable/DataRow with very similar API:\n```\nvar rs = dbAdapter.Select(new Query(\"Employees\")).ToRecordSet();\nrs.SetPrimaryKey(\"EmployeeID\");\nforeach (var row in rs) {\n\tConsole.WriteLine(\"ID={0}\", row[\"EmployeeID\"]);\n\tif (\"Canada\".Equals(row[\"Country\"]))\n\t\trow.Delete();\n}\ndbAdapter.Update(rs);\nvar rsReader = new RecordSetReader(rs); // DbDataReader for in-memory rows\n```\n**[Relex](https://github.com/nreco/data/wiki/Relex)** - compact relational query expressions:\n```\nvar relex = @\"Employees(BirthDate\u003e\"\"1960-01-01\"\":datetime)[Name,BirthDate]\"\nvar relexParser = new NReco.Data.Relex.RelexParser();\nQuery q = relexParser.Parse(relex);\n```\n\n## More examples\n* [Command Builder](https://github.com/nreco/data/tree/master/examples/SqliteDemo.CommandBuilder/Program.cs): illustrates SQL commands generation, command batching (inserts)\n* [Data Adapter](https://github.com/nreco/data/tree/master/examples/SqliteDemo.DataAdapter/Program.cs): CRUD operations with dictionaries, POCO, RecordSet\n* [DataSet GenericDataAdapter](https://github.com/nreco/data/blob/master/examples/DataSetGenericDataAdapter/Program.cs): how to implement generic DataSet DataAdapter (Fill/Update) for any ADO.NET provider \n* [SQL logging](https://github.com/nreco/data/tree/master/examples/SqliteDemo.SqlLogging): how to extend `DbFactory` and add wrapper for `DbCommand` that logs SQL commands produced by `DbDataAdapter`\n* [DB WebApi](https://github.com/nreco/data/tree/master/examples/SqliteDemo.WebApi): configures NReco.Data services in MVC Core app, simple REST API for database tables\n* [MVC Core CRUD](https://github.com/nreco/data/tree/master/examples/SqliteDemo.MVCApplication): full-functional CRUD (list, add/edit forms) that uses NReco.Data as data layer in combination with EF Core\n* [DB Metadata](https://github.com/nreco/data/tree/master/examples/MySqlDemo.DbMetadata): extract database metadata (list of tables, columns) with information_schema queries\n* [GraphQL API for SQL database](https://github.com/nreco/data/tree/master/examples/SqliteDemo.GraphQLApi): provides simple GraphQL API by existing database schema (simple queries only, no mutations yet)\n\n## Who is using this?\nNReco.Data is in production use at [SeekTable.com](https://www.seektable.com/) and [PivotData microservice](https://www.nrecosite.com/pivotdata_service.aspx).\n\n## License\nCopyright 2016-2023 Vitaliy Fedorchenko and contributors\n\nDistributed under the MIT license\n","funding_links":[],"categories":["Frameworks, Libraries and Tools","HarmonyOS","框架, 库和工具","ORM","C\\#","C# #"],"sub_categories":["ORM","Windows Manager","对象关系映射ORM"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnreco%2Fdata","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnreco%2Fdata","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnreco%2Fdata/lists"}