I was using Dapper and having it return a dynamic IEnumerable, like this:
var rows = conn.Query("SELECT * FROM T WHERE ID = @id", new { id = tableId });
var row = rows.FirstOrDefault();
Here, rows
is of type IEnumerable<dynamic>
. The IntelliSense says FirstOrDefault()
is awaitable, and has the usage await FirstOrDefault()
. Not all LINQ queries are shown as awaitable, but it seems like especially those that somehow single out elements are.
As soon as I instead use strong typing, this behavior goes away.
Is it because .NET can't know if the type you are receiving at runtime is awaitable or not, so that it "allows" it, in case you need it? But doesn't enforce it? Or am I supposed to, due to some Dynamic Language Runtime behavior, actually use await
here?
I have kept searching but not found the smallest thing about this online.
GetAwaiter()
ondynamic
, so yes it awaitable. – user4003407 Oct 9 '15 at 9:24