1

I am trying to select a list of objects from the db with a direct SQL command. db is my dbContext

List<long> ids = db.Database.SqlQuery<List<long>>(sqlCommand).ToList(); 

My query, when tested in SQL (not that visual studio knows this) returns a list of ids, which are of type long. I want to return this list. I use ToList() to force execution (since it's deferred until enumerated). However, I get a compile error saying that I cannot implicitly convert a generic list to list of type long.

enter image description here

How do I specify to List<long>? This might be a completely stupid question, but I thought it took something of T and converted it to a list of T, which should be List<long> here.

Community
  • 1
  • 1
VSO
  • 11,546
  • 25
  • 99
  • 187

1 Answers1

3

Simple, just make it as follows:

List<long> ids = db.Database.SqlQuery<long>(sqlCommand).ToList();
RizJa
  • 1,961
  • 1
  • 21
  • 38