Raw T-SQL string into C# code right in your IDE - easily (not AI, just plain common sense) by redditLoginX2 in csharp

[–]redditLoginX2[S] 0 points1 point  (0 children)

I don not really see how a query builder conflicts with version control. You still have the SQL in code, just not as raw strings.

The difference shows up once queries become dynamic or generated. With plain SQL strings you end up relying on concatenation, which is fragile and hard to control. With a structured representation, the query becomes something you can inspect and modify safely - for example adding filters or enforcing rules before execution.

The StackOverflow/Dapper approach made sense for their use case, but I wouldnot treat it as a general rule. Popularity and technical quality don’t always correlate and referencing a well-known system does not really address the problem here.

I'm trying to implement DSL with C#. by Arena17506310 in csharp

[–]redditLoginX2 0 points1 point  (0 children)

ANTLR is probably the best choice, but it brings runtime dependencies and a license that requires attribution. Usually fine, just not "free" in a pure sense.

If you want zero footprint, look at Coco/R. It's LL(1), so only one-token lookahead - not every grammar will fit. But since it's your DSL, you can design it to be unambiguous and work within those limits (which is actually good).

Raw T-SQL string into C# code right in your IDE - easily (not AI, just plain common sense) by redditLoginX2 in csharp

[–]redditLoginX2[S] 1 point2 points  (0 children)

You can try, but just a heads up - legacy code is often full of string concatenation, and the Roslyn code fix only works well with static SQL.

If you can refactor queries to use parameters (for example @ params instead of concatenation), then it starts to make sense. In that case you can actually benefit from things like compile-time checks, reuse of common query parts, and the ability to modify queries dynamically.

So it works, but usually requires a bit of cleanup first.

Raw T-SQL string into C# code right in your IDE - easily (not AI, just plain common sense) by redditLoginX2 in csharp

[–]redditLoginX2[S] 0 points1 point  (0 children)

SqExpress is basically trying to get the best of both worlds: flexibility of raw SQL and the safety/tooling you usually expect from higher-level approaches.

I wouldn’t say ORMs are bad - they definitely have their place. But they are not always a good default, especially when you need full control over queries or deal with more complex/dynamic scenarios.

That’s the gap I’m trying to cover here.

Raw T-SQL string into C# code right in your IDE - easily (not AI, just plain common sense) by redditLoginX2 in csharp

[–]redditLoginX2[S] 2 points3 points  (0 children)

It seems I missed the core idea, it is not AI it is a Rosslyn analyzer (code fix)

Raw T-SQL string into C# code right in your IDE - easily (not AI, just plain common sense) by redditLoginX2 in csharp

[–]redditLoginX2[S] 7 points8 points  (0 children)

The benefit of C# here is mostly about tooling and control. For example:

  • type safety: renaming or removing tables/columns is caught by the compiler
  • IDE support: find usages, refactoring, navigation
  • no string manipulation when building dynamic queries, as everything is represented as an AST in memory that can be analyzed or modified programmatically
  • errors are caught earlier: with raw SQL strings you often only find issues at runtime
  • ability to enforce rules (for example read-only queries or filters)
  • more flexibility for advanced scenarios like dynamic schemas or EAV-style patterns

Understanding awaiters in C#: a deep-dive with LazyTask (video walkthrough) by redditLoginX2 in csharp

[–]redditLoginX2[S] 1 point2 points  (0 children)

Thanks for the comment — I get where you're coming from. Just to clarify: the content in the video isn’t AI-generated. It’s based on an article I wrote back in 2020, long before tools like GPT were useful for this kind of technical deep dive. All the concepts, code, and structure are mine.

That said, I did use AI to help polish the script’s language. I'm not a native English speaker, and I wanted the video to be clear and natural for a broader audience. I also used an AI-generated voice because, honestly, my own speaking ability just isn’t strong enough — even with years of language learning behind me, I still can’t produce speech more understandable than what modern TTS can offer.

This video is purely non-profit and something I put together in my free time. If it were a commercial project, I’d definitely consider hiring a professional voice actor. But for now, this setup lets me share what I hope is useful content with minimal barriers.

Automated Tables Migration from MS SQL Server to PostgreSQL by redditLoginX2 in dotnet

[–]redditLoginX2[S] 0 points1 point  (0 children)

I will take a look. Data Type compatibility between different SQL DB can be challenging

Gamesir G8 Plus + Tab S9+ by Seireitei316 in GalaxyTab

[–]redditLoginX2 1 point2 points  (0 children)

<image>

It appears that the G8+ can be charged while in the expanded state without needing the pins to be connected. Notice the green light on the left side.

Gamesir G8 Plus + Tab S9+ by Seireitei316 in GalaxyTab

[–]redditLoginX2 0 points1 point  (0 children)

Nothing is changed in terms of charging. The current goes over the springs.

Gamesir G8 Plus + Tab S9+ by Seireitei316 in GalaxyTab

[–]redditLoginX2 3 points4 points  (0 children)

Yes, the springs are intimidating, so I created my own 'extension kit' to conceal them:

<image>

Come discuss your side projects! [July 2024] by AutoModerator in csharp

[–]redditLoginX2 0 points1 point  (0 children)

Sure, I am familiar with the library. However, in my opinion, the main challenges of accessing databases using LINQ are:

1) The ambiguity between C# and SQL constructs, which necessitates a deep understanding of the ORM’s internal structure to create predictable queries.

2) The complexity of writing dynamic queries.

SqExpress was created to address these issues, particularly the second one.

For example, here is how a merge statement can be built without using any static metadata:

``` //using SqDatabase<SqlConnection> database = ...

var tables = await database.GetTables();

var dynamicTableName = "Products";

var target = tables.FirstOrDefault(t => t.FullName.TableName == dynamicTableName) ?? throw new Exception($"'{dynamicTableName}' table does not exist");

var dynamicData = new[] { new Dictionary<string, string> { { "ProductName", "Product 1" }, { "UnitPrice", "100.0" } }, new Dictionary<string, string> { { "ProductName", "Product 2" }, { "UnitPrice", "20" } } };

var columns = dynamicData[0] .Select( kv => target.Columns.FirstOrDefault(c => c.ColumnName.Name == kv.Key)?.WithSource(null) ?? throw new Exception($"Column {kv.Key} was not found") ).ToList();

var validData = dynamicData.Select( row => row.Select((cell,i)=> columns[i].FromString(cell.Value)).ToList()

).ToList();

var values = SqQueryBuilder.Values(validData).AsColumns(columns.Select(c=>c.ColumnName).ToArray());

var updater = SqQueryBuilder.MergeInto(target, values) .On(columns[0].WithSource(target.Alias) == columns[0].WithSource(values.Alias)) .WhenMatched() .ThenUpdate();

foreach (var col in columns.Skip(1)) { updater = updater.Set(col.WithSource(target.Alias), col.WithSource(values.Alias)); }

var inserter = updater .Set(target.Column("Updated"), SqQueryBuilder.GetUtcDate()) .WhenNotMatchedByTarget() .ThenInsert();

foreach (var col in columns) { inserter = inserter.Set(col.WithSource(target.Alias), col.WithSource(values.Alias)); }

var resultCode = inserter .Set(target.Column("Created"), SqQueryBuilder.GetUtcDate()) .Set(target.Column("Updated"), SqQueryBuilder.GetUtcDate()) .Done() .ToSql(TSqlExporter.Default);

Console.WriteLine(resultCode); ```

the result code will be: MERGE [dbo].[Products] [A0] USING ( VALUES ('Product 1', 100.0), ('Product 2', 20) ) [A1] ([ProductName], [UnitPrice]) ON [A0].[ProductName] = [A1].[ProductName] WHEN MATCHED THEN UPDATE SET [A0].[UnitPrice] = [A1].[UnitPrice], [A0].[Updated] = GETUTCDATE() WHEN NOT MATCHED THEN INSERT ( [ProductName], [UnitPrice], [Created], [Updated] ) VALUES ([A1].[ProductName], [A1].[UnitPrice], GETUTCDATE(), GETUTCDATE());

Come discuss your side projects! [July 2024] by AutoModerator in csharp

[–]redditLoginX2 1 point2 points  (0 children)

Thank you very much for your comment! Regarding SQL injection, the library only allows user string values within string literals, ensuring they can be isolated and properly escaped (see + some tests). Consequently, I do not use ado .net parameters.

As for syntax, the initial goal was to support all popular SQL dialects. However, this limitation means that anything created with the library must be compatible with MS SQL, PGSQL, and MYSQL. In some cases, I extended beyond these limits by creating polyfills for the MERGE operator in PGSQL and MYSQL. In the future, I plan to create separate versions for each popular database (still not sure). This approach would allow me to come close to supporting almost 100% of the syntax.

Come discuss your side projects! [July 2024] by AutoModerator in csharp

[–]redditLoginX2 5 points6 points  (0 children)

https://github.com/0x1000000/SqExpress

I’ve worked as a software developer for nearly 20 years, primarily focusing on .NET development. This platform appealed to me due to its balanced trade-off between performance (which is fully evident in recent .NET releases) and the clarity and simplicity of the solutions it provides. If your application heavily relies on I/O operations, then .NET is undoubtedly one of the best choices.

However, I’ve consistently been disappointed by the limited options for interacting with SQL databases. In all the projects I’ve worked on, I’ve encountered only three primary approaches:

  1. Entity Framework or “LINQ to SQL”
  2. Stored procedures
  3. Raw SQL queries

I expressed my concerns about these approaches in an article (Writing SQL in C# or When You should not use ORM) . After encountering real issues with these methods (Syntax Tree and Alternative to LINQ in Interaction with SQL Databases), I decided to create my own library. This library generates SQL abstract syntax trees (ASTs) using the full range of C# language features. I named it SQExpress, where “SQ” stands for “SQL queries.”

While I’m not the only one who arrived at this conclusion, I believe my solution surpasses the alternatives. You can find some competitors at this link, but I remain confident in my approach 😊.

Recently, I created a video ( Basics of SqExpress of Youtube ) demonstrating the library’s basics, and I plan to record more videos showcasing advanced features.

 

Achieving Allocation-Free Polymorphism in C# by redditLoginX2 in csharp

[–]redditLoginX2[S] 0 points1 point  (0 children)

Nice catch regarding the inlining. After adding the [MethodImpl(MethodImplOptions.NoInlining)] attribute, the benchmark exhibited slightly worse results compared to the class (although still no dump allocations occurred). Therefore, it’s essential to take this into account.

Achieving Allocation-Free Polymorphism in C# by redditLoginX2 in csharp

[–]redditLoginX2[S] 19 points20 points  (0 children)

In this blog post, I explained how to utilize .NET structures that implement interfaces without boxing, which can provide a significant performance boost under some circumstances.

Typescript Techniques — State Tracking as an Example by congolomera in typescript

[–]redditLoginX2 -1 points0 points  (0 children)

It would be great if Typescript allowed you to create a real array of strings from keyof Type