I am having an issue with "carrying forward" the results of a DAL-level class to my BLL class of the same definition.
Error: "Unable to cast object of type 'DeserializedGame' to type 'DeserializedGameBLL'."
//DAL Classes
public class GameCollection{
public List<DeserializedGame> Games { get; set; }
public int RefreshInterval { get; set; }
public string CurrentDate { get; set; }
public string NextDate { get; set; }
public string PrevDate { get; set; }
}
public class DeserializedGame
{
public string Atcommon { get; set; }
public string Canationalbroadcasts { get; set; }
public string Ata { get; set; }
public bool Rl { get; set; }
public int Atsog { get; set; }
public string Bs { get; set; }
public string Htcommon { get; set; }
public int Id { get; set; }
public string Atn { get; set; }
public int Hts { get; set; }
public string Atc { get; set; }
public string Htn { get; set; }
public string Usnationalbroadcasts { get; set; }
public bool Gcl { get; set; }
public string Hta { get; set; }
public int? Ats { get; set; }
public string Htc { get; set; }
public int Htsog { get; set; }
public string Bsc { get; set; }
public int Gs { get; set; }
public bool Gcll { get; set; }
}
//BLL Classes
public class GameCollectionBLL : IEnumerable
{
public List<DeserializedGame> Games { get; set; }
public int RefreshInterval { get; set; }
public string CurrentDate { get; set; }
public string NextDate { get; set; }
public string PrevDate { get; set; }
public GameCollectionBLL(List<DeserializedGame> gameList, int refreshInterval, string currentDate,
string nextDate, string previousDate)
{
this.Games = gameList;
this.RefreshInterval = refreshInterval;
this.CurrentDate = currentDate;
this.NextDate = nextDate;
this.PrevDate = previousDate;
}
public IEnumerator GetEnumerator()
{
return (Games as IEnumerable).GetEnumerator();
}
}
public class DeserializedGameBLL : BaseSeasonSchedule
{
public string Atcommon { get; set; }
public string Canationalbroadcasts { get; set; }
public string Ata { get; set; }
public bool Rl { get; set; }
public int Atsog { get; set; }
public string Bs { get; set; }
public string Htcommon { get; set; }
public int Id { get; set; }
public string Atn { get; set; }
public int Hts { get; set; }
public string Atc { get; set; }
public string Htn { get; set; }
public string Usnationalbroadcasts { get; set; }
public bool Gcl { get; set; }
public string Hta { get; set; }
public int? Ats { get; set; }
public string Htc { get; set; }
public int Htsog { get; set; }
public string Bsc { get; set; }
public int Gs { get; set; }
public bool Gcll { get; set; }
}
public abstract class BaseSeasonSchedule
{
public int GameID { get; set; }
public DateTime GameDate { get; set; }
}
//UI usage
public partial class Form1 : Form
{
private SeasonSheduleBLL objSeasonSchedule = new SeasonSheduleBLL();
private void button1_Click(object sender, EventArgs e)
{
GameCollectionBLL gameDay = objSeasonSchedule.GetGameCollection(json_string);
foreach (DeserializedGameBLL game in gameDay) //error occurs here when referencing the DeserialzedGameBLL
{
// do stuff here
}
}
}
What do I need to do to make my DeserialzedGame collection work properly?
I have looked at this question (and attempted to follow @Measuring advice in the original post). I have considered (and still haven't elimiated using DTO's, but I am unsure how to use them correctly).
If this belongs in the Code Review section, I will happily post in there instead, but I thought enough people might be experiencing the same frustration a I am.