| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
There was a problem hiding this comment.
Adds a generic Query.Select<T>() API to infer selected columns from a CLR type’s public properties (with optional [Column] attribute mapping), along with tests validating the generated SQL for PostgreSQL.
Changes:
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| QueryBuilder/Query.Select.cs | Introduces Select<T>() implementation using reflection and [Column] attributes. |
| QueryBuilder.Tests/SelectTests.cs | Adds tests to validate generated SQL for Select<T>() with and without [Column]. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Sorry, something went wrong.
| public Query Select<T>() where T : class { | ||
| var properties = typeof(T).GetProperties(); | ||
| var columns = new List<string>(); | ||
| foreach (var property in properties) { | ||
| if (property.GetSetMethod() == null) { | ||
| continue; | ||
| } | ||
|
|
||
| var name = property.Name; | ||
| var attribute = property.GetCustomAttribute<ColumnAttribute>(); | ||
| if (attribute != null) { | ||
| name = $"{attribute.Name} as {name}"; | ||
| } | ||
|
|
||
| columns.Add(name); | ||
| } |
| foreach (var property in properties) { | ||
| if (property.GetSetMethod() == null) { | ||
| continue; | ||
| } |
| } | ||
|
|
||
| public Query Select<T>() where T : class { | ||
| var properties = typeof(T).GetProperties(); |
| public Query Select<T>() where T : class { | ||
| var properties = typeof(T).GetProperties(); | ||
| var columns = new List<string>(); |
| public void SelectType() { | ||
| var q = new Query("Post").Select<Post>(); | ||
|
|
||
| var pgsql = Compilers.CompileFor(EngineCodes.PostgreSql, q); | ||
|
|
||
| Assert.Equal(""" | ||
| SELECT "Id", "Title", "Published" FROM "Post" | ||
| """, pgsql.ToString()); |
| Back | FazBrowse Home | New Git URL |
Add Select<T>() to automatically add all the properties of a class into select component.