In the code below, I am converting the results of an SQL View to a DataTable:
DataTable tierOnes = db.xxxxxxxxx_vw_TierOnes.ToDataTable();
The View is defined in a separate class:
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace DPN.Entities.Moonboot
{
[Table("vw_TierOnes", Schema = "xxxxxxxxx")]
public class xxxxxxxxx_vw_TierOnes
{
[Key]
public Guid TierOneID { get; set; }
public string TierOneName { get; set; }
public DateTime DateCreated { get; set; }
public Boolean IsActive { get; set; }
public int? CreatedByUserID { get; set; }
}
}
I try to retrieve data from columns AS BELOW:
foreach (DataRow row in tierOnes.Rows)
{
if (row["IsActive"].ToString() == "True")
{
TierOne t1 = new TierOne();
t1.Id = Guid.Parse(row["TierOneID"].ToString());
t1.Name = row["TierOneName"].ToString();
output.TierOnes.Add(t1);
}
}
I get the following error:
Column 'TierOneID' does not belong to table .
Where did my column go? More importantly, how do I get this data?