question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support object/dynamic in SqlQueryValueAsync

See original GitHub issue

I have a use case where I must query a dynamic database (columns might get added/removed by another system). I have a query generator that generates raw SQL queries.

I’d like to be able to do this:

var data = await _context.SqlQueryValueAsync<IEnumerable<object>>(query, cancellationToken: cancellationToken); or var data = await _context.SqlQueryValueAsync<IEnumerable<dynamic>>(query, cancellationToken: cancellationToken);

or

var data = await _context.SqlQueryValueAsync<object>(query, cancellationToken: cancellationToken); or var data = await _context.SqlQueryValueAsync<dynamic>(query, cancellationToken: cancellationToken);

Currently, I’m getting: System.NotSupportedException: Invalid operation, supplied type is not a value type

Provide steps to reproduce

Consider a query like this: SELECT TOP 100 * from dbo.Users; or SELECT name, surname, agefrom dbo.Users where id=1234;

Provide technical details

Searching over the net I found this: https://github.com/dotnet/efcore/issues/2344#issuecomment-172641417, but ideally, this should be added to this library.

  • EF Core version in use: (e.g. EF Core 6)

  • Is Handlebars used: no/yes

  • Is .dacpac used: no/yes

  • EF Core Power Tools version: (found in About dialog - blue questionmark icon on context menu)

  • Database engine: (SQL Server, Azure SQL, Postgres, Oracle, Firebird, SQLite, MySQL)

  • Visual Studio version: (e.g. Visual Studio 2022)

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ErikEJcommented, Sep 30, 2022
0reactions
Misiucommented, Sep 30, 2022

Could you please add link to EF Core issue for that?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is it better to have separate query functions or one dynamic ...
Simply pass in the SQL string and parameters. This works and makes more sense with stored procedures which is what I recommend you...
Read more >
Dos and Don'ts of Dynamic SQL
One thing that is incredibly important when using dynamic SQL is making sure your object names are properly quoted. That means not injecting ......
Read more >
Performing Asynchronous Operations - SQL Server Native ...
SQL Server allows applications to perform asynchronous database operations. Asynchronous processing enables methods to return immediately ...
Read more >
Dynamic Data Access with Plain Old SQL and SqlQuery
SqlQuery returns a DbRawSqlQuery object that you can use to manage your query (as with a LINQ query, your SQL query isn't passed...
Read more >
Execute a query and map it to a list of dynamic objects #2344
SqlQuery to support dynamic type for map query to a list of dynamic objects. for example: var results = DbContext.Database.SqlQuery ("SELECT ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found