C
C#•7mo ago
Indeed

SQL EFCore

Hi! What's current way to query db for data using raw sql? Im used to doing it this way from Doctrinedb and php Something like MyModel[] x = query("SELECT ..."); Rather than using an orm
10 Replies
Indeed
IndeedOP•7mo ago
Especially for more complex queries
Angius
Angius•7mo ago
Oh, that's easily googleable
Angius
Angius•7mo ago
But if you don't want to use EF... why use EF?
Indeed
IndeedOP•7mo ago
coming back after a long time to c#, apologies 😅 Was looking for context.Database.SqlQuery<>() I do not really have too much of an idea what other tools are there for such thing
Angius
Angius•7mo ago
Dapper, for example
Jimmacle
Jimmacle•7mo ago
or linq2db if you want to write more advanced queries without dropping all the way to raw SQL
The Fog from Human Resources
Dapper does a great job for what you want to achieve And it's super flexible in terms of what Databases work :soPortuguese:
Indeed
IndeedOP•7mo ago
Speaking of, Dapper support FormatableSQLStrings? Rider has amazing support for SQL strings but not dapper
Result<int> affected = await Result.Try(() => this._context.GetConnection().ExecuteAsync($"""
INSERT INTO users (username, password)
VALUES (@username, @password)
""", new { username, password = password.ToString() }));
Result<int> affected = await Result.Try(() => this._context.GetConnection().ExecuteAsync($"""
INSERT INTO users (username, password)
VALUES (@username, @password)
""", new { username, password = password.ToString() }));
Result<int> affected = await Result.Try(() => this._context.Database.ExecuteSqlAsync($"""
INSERT INTO users (username, password)
VALUES ({username}, {password.ToString()})
"""));
Result<int> affected = await Result.Try(() => this._context.Database.ExecuteSqlAsync($"""
INSERT INTO users (username, password)
VALUES ({username}, {password.ToString()})
"""));
Indeed
IndeedOP•7mo ago
No description
Want results from more Discord servers?
Add your server