This code:
IList<string> quids;
quids = db.Database.SqlQuery<string>("dbo.getById @Id",
new SqlParameter { ParameterName = "Id", Value = 1 });
Produces the following error message:
Cannot implicitly convert type 'System.Data.Entity.Infrastructure.DbRawSqlQuery' to 'System.Collections.Generic.IList'.
An explicit conversion exists (are you missing a cast?)
Can someone explain to me how I can cast a collection?
IList<string> result = oldCollection.ToList();
DbRawSqlQuery<T>
Does not implement the IList<T>
interface (so, no direct cast possible). But it implements IEnumerable<T>
, so you can call .ToList()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With