How can i make a collection

This code:

IList<string> quids;
quids = db.Database.SqlQuery<string>("dbo.getById @Id",
                new SqlParameter { ParameterName = "Id", Value = 1 });

It produces the following error message:

It is not possible to implicitly convert the type 'System.Data.Entity.Infrastructure.DbRawSqlQuery' to 'System.Collections.Generic.IList.

An explicit conversion exists (do you miss the role?)

Can someone explain to me how I can hide the collection?

+4
source share
1 answer
IList<string> result = oldCollection.ToList();

DbRawSqlQuery<T>Does not implement the interface IList<T>(therefore, live broadcasting is not possible). But it implements IEnumerable<T>, so you can call .ToList().

+8
source

Source: https://habr.com/ru/post/1546107/


All Articles