IEnumerable to Object?

c# entity-framework-6

Question

I'm not really sure how this works. I've got anIEnumerable<T> list that I'm obtaining from a mySql database's stored method.

       IEnumerable<CheckInVar> CheckInVars = context.Database.SqlQuery<CheckInVar>(
          "Call getCheckinVars(\"WEB\")").ToList();

Do I really need to cycle over this object in order to extract the attributes and utilize them in this way?

foreach (var prop in CheckInVars.GetType().GetProperties())
        {

            Console.WriteLine("{0} = {1}", prop.Name, prop.GetValue(CheckInVars, null));
        }

or can I use that information directly?IEnumberable<CheckInVar> Do I need to transform it in order to use it as an object?

public class CheckInVar
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.None)]
    [Column("ID")]
    public int ID { get; set; }
    public string Code { get; set; }
    public string VarValue { get; set; }
    public string AccessMethod { get; set; }
    public string Active { get; set; }
    public string DateCreated { get; set; }
    public string DateUpdated { get; set; }
    public string UpdatedBy { get; set; }
}
1
0
11/16/2016 10:17:48 PM

Accepted Answer

ZZZ_tmp
1
11/16/2016 11:10:23 PM

Popular Answer

Consider using foreach

IEnumerable<CheckInVar> CheckInVars = context.Database.SqlQuery<CheckInVar>(
    "Call getCheckinVars(\"WEB\")").ToList();

foreach(CheckInVar item in CheckInVars)
{
    Console.WriteLine("ID: " + item.ID.ToString());
    Console.WriteLine("Code: " + item.Code);
    Console.WriteLine("VarValue: " + item.VarValue);
    //....
}


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow