{"id":13734449,"url":"https://github.com/gambarra/ExpressionExtensionSQL","last_synced_at":"2025-05-08T10:31:54.170Z","repository":{"id":93247177,"uuid":"160349464","full_name":"gambarra/ExpressionExtensionSQL","owner":"gambarra","description":null,"archived":false,"fork":false,"pushed_at":"2024-06-28T08:08:51.000Z","size":2397,"stargazers_count":40,"open_issues_count":1,"forks_count":11,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-08-03T03:03:39.213Z","etag":null,"topics":["builder","dapper","dotnet","dotnet-core","expression","predicate","sql"],"latest_commit_sha":null,"homepage":"https://www.nuget.org/packages/ExpressionExtensionSQL/","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/gambarra.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":"2018-12-04T11:49:28.000Z","updated_at":"2024-08-03T03:03:39.925Z","dependencies_parsed_at":"2023-04-15T09:32:28.850Z","dependency_job_id":null,"html_url":"https://github.com/gambarra/ExpressionExtensionSQL","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gambarra%2FExpressionExtensionSQL","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gambarra%2FExpressionExtensionSQL/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gambarra%2FExpressionExtensionSQL/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gambarra%2FExpressionExtensionSQL/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gambarra","download_url":"https://codeload.github.com/gambarra/ExpressionExtensionSQL/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224720956,"owners_count":17358485,"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":["builder","dapper","dotnet","dotnet-core","expression","predicate","sql"],"created_at":"2024-08-03T03:00:55.927Z","updated_at":"2024-11-15T02:32:43.298Z","avatar_url":"https://github.com/gambarra.png","language":"C#","readme":"ExpressionExtensionSQL - is a sample lambda expression to sql converter .NET\n========================================\n[![Codacy Badge](https://api.codacy.com/project/badge/Grade/12a0ce6a259141e5949289ded24f7377)](https://app.codacy.com/app/tgambarra/ExpressionExtensionSQL?utm_source=github.com\u0026utm_medium=referral\u0026utm_content=gambarra/ExpressionExtensionSQL\u0026utm_campaign=Badge_Grade_Dashboard)\n\nPackages\n--------\n\nNugget feed: https://www.nuget.org/packages/ExpressionExtensionSQL/\n\n| Package | NuGet Stable | NuGet Pre-release | Downloads |\n| ------- | ------------ | ----------------- | --------- | \n[ExpressionExtensionSQL](https://www.nuget.org/packages/ExpressionExtensionSQL/) | [![ExpressionExtensionSQL](https://img.shields.io/nuget/v/ExpressionExtensionSQL.svg)](https://www.nuget.org/packages/ExpressionExtensionSQL/) | [![ExpressionExtensionSQL](https://img.shields.io/nuget/vpre/ExpressionExtensionSQL.svg)](https://www.nuget.org/packages/ExpressionExtensionSQL/) | [![ExpressionExtensionSQL](https://img.shields.io/nuget/dt/ExpressionExtensionSQL.svg)](https://www.nuget.org/packages/ExpressionExtensionSQL/) |\n| [ExpressionExtensionSQL.Dapper](https://www.nuget.org/packages/ExpressionExtensionSQL.Dapper/) | [![ExpressionExtensionSQL.Dapper](https://img.shields.io/nuget/v/ExpressionExtensionSQL.Dapper.svg)](https://www.nuget.org/packages/ExpressionExtensionSQL.Dapper/) | [![ExpressionExtensionSQL.Dapper](https://img.shields.io/nuget/vpre/ExpressionExtensionSQL.Dapper.svg)](https://www.nuget.org/packages/ExpressionExtensionSQL.Dapper/) | [![ExpressionExtensionSQL.Dapper](https://img.shields.io/nuget/dt/ExpressionExtensionSQL.Dapper.svg)](https://www.nuget.org/packages/ExpressionExtensionSQL.Dapper/) |\n\nFeatures\n--------\nExpressionExtensionSQL is a [NuGet library](https://www.nuget.org/packages/ExpressionExtensionSQL) which you can add to your project to achieve lambda expression in SQL code. It allows your domain doesn't need to understand  SQL language mainly for creating filters. Very suitable for use with [SpecificationPattern](https://en.wikipedia.org/wiki/Specification_pattern).\n\nSamples:\n\n```\nExample usage:\n```\n```csharp\n Expression\u003cFunc\u003cMerchant, bool\u003e\u003e expression = x =\u003e x.Name == \"merchant1\" \u0026\u0026 x.CreatedAt\u003e=DateTime.Now;\n var where = expression.ToSql();\n Console.Write(where.Sql);\n \n```\nOutput will be:\n```\n([Merchant].[Name] = @1) AND ([Merchant].[CreatedAt]\u003e=@2)\n```\n\n**where.Parameters** contains a list of parameters that can be used in ADO queries.\n\nIn many cases the name of the table or column in the database is different from the name of the entity or property. For these cases this framework allows to create a mapping through attribute or fluent mapping.\n\n## Attribute \n\nClass\n\n```csharp\n   [TableName(\"tblOrder\")]\n    public class Order {\n\n        public int Id { get; set; }\n        public DateTime CreatedAt { get; set; }\n        [ColumnName(\"amount\")]\n        public int TotalAmount { get; set; }\n    }\n```\n```\nExample usage:\n```\n```csharp\n Expression\u003cFunc\u003cOrder, bool\u003e\u003e expression = x =\u003e x.TotalAmount \u003e10 \u0026\u0026 x.CreatedAt\u003e=DateTime.Now;\n var where = expression.ToSql();\n Console.Write(where.Sql);\n \n```\nOutput will be:\n```\n([tblOrder].[amount] = @1) AND ([tblOrder].[CreatedAt]\u003e=@2)\n```\n\n### Classes that have inheritance, their superclasses must be defined as abstract. Otherwise, the table name will be equivalent to that of the parent class.\n```\nExample usage:\n```\nIf the classes are declared like below:\n```\npublic class Entity {\n    public int Id { get; set; }\n    public DateTime CreatedAt { get; set; }\n}\npublic class Merchant : Entity {        \n    public string Name { get; set; }\n}\n\n...\n\nExpression\u003cFunc\u003cMerchant, bool\u003e\u003e expression = x =\u003e x.Id == 1;\n var where = expression.ToSql();\n Console.Write(where.Sql);\n```\nThe previous usage example, will be output like this:\n```\n([Entity].[Id] = @1)\n```\n\nBut, if the **Entity** class was an abstract class, the output would be like this:\n```\n([Merchant].[Id] = @1)\n```\n\n## Fluent Mapping\nClass\n\n```csharp\n    public class Order {\n\n        public int Id { get; set; }\n        public DateTime CreatedAt { get; set; }\n        public int TotalAmount { get; set; }\n    }\n```\n```\nExample usage:\n```\n```csharp\n\n Configuration.GetInstance().Entity\u003cOrder\u003e().ToTable(\"tblTeste\");\n Configuration.GetInstance().Entity\u003cOrder\u003e().Property(p =\u003e p.TotalAmount).ToColumn(\"valor\");\n \n Expression\u003cFunc\u003cOrder, bool\u003e\u003e expression = x =\u003e x.TotalAmount \u003e10 \u0026\u0026 x.CreatedAt\u003e=DateTime.Now;\n var where = expression.ToSql();\n Console.Write(where.Sql);\n \n```\nOutput will be:\n```\n([tblTeste].[valor] = @1) AND ([tblTeste].[CreatedAt]\u003e=@2)\n```\n\nThe **Configuration** class is static and can be used anywhere on your system and the configured mapping is reused for all expressions that contain the mapped entity\n\nExpressExtensionSQL.Dapper\n--------\nExpressionExtensionSQL.Dapper is an dapper extension that allows you to use lambda expressions as filters in your Query.\n\nSamples:\n```csharp\n\n        public IQueryable\u003cPeriod\u003e GetAll(Expression\u003cFunc\u003cOrder, bool\u003e filter) {\n\n            var query = $@\"SELECT * FROM [Order]\n                            {{where}}\"\n\n            var connection = this.GetConnection();\n\n            return connection.Query\u003cOrder\u003e(query, expression: filter);\n         }\n```\n```csharp\nvar result=OrderRepository.GetAll(p=\u003ep.CreatedAt\u003e=DateTime.Now);\n```\nIn the above example it is important to note the use of {where}. This keyword will tell you where to include the where clause extracted from the expression.\n","funding_links":[],"categories":["sql","Libraries","C# #"],"sub_categories":["ORM and Micro-ORM"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgambarra%2FExpressionExtensionSQL","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgambarra%2FExpressionExtensionSQL","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgambarra%2FExpressionExtensionSQL/lists"}