I have the following type:
public class TimeBand
{
public string DayName { get; set; }
public int customerId { get; set; }
}
and I am creating a list which contains TimeBands:
var TimeBandList = new List<TimeBand>
{
new TimeBand()
{
DayName = DayOfWeek.Monday.ToString(),
customerId = 10
},
new TimeBand()
{
DayName = DayOfWeek.Tuesday.ToString(),
customerId = 11
}
.....
};
And I am using the following to load TimeBands into another List:
var timeBandRange = new List<TimeBand>();
timeBandRange = TimeBandList.Where
(p => p.customerId == newCustomerId
&& p.DayName == date.DayOfWeek.ToString()).ToList();
This was working fine but in the TimeBand class I decided to change the type of the DayName property to DayOfWeek from string so the code has become like this:
public class TimeBand
{
public DayOfWeek DayName { get; set; }
public int customerId { get; set; }
}
var TimeBandList = new List<TimeBand>
{
new TimeBand()
{
DayName = DayOfWeek.Monday,
customerId = 10
},
new TimeBand()
{
DayName = DayOfWeek.Tuesday,
customerId = 11
}
.....
};
DateTime date = IndDate;
var timeBandRange = new List<TimeBand>();
timeBandRange = TimeBandList.Where
(p => p.customerId == parameter.customerId
&& p.DayName == date.DayOfWeek).ToList();
This new code is now failing on the TimeBandList.Where line and giving the following error: System.MissingMethodException: Method not found: 'System.String TimeBand.get_DayName()'.
Any idea why?
Thanks
Perhaps you only need to recompile? I ran this code locally and it worked fine.
class Program
{
static void Main(string[] args)
{
TimeBand.DoSomething();
}
}
public class TimeBand
{
public DayOfWeek DayName { get; set; }
public int customerId { get; set; }
public static void DoSomething()
{
var TimeBandList = new List<TimeBand>
{
new TimeBand()
{
DayName = DayOfWeek.Monday,
customerId = 10
},
new TimeBand()
{
DayName = DayOfWeek.Tuesday,
customerId = 11
}
};
DateTime date = DateTime.Now;
var timeBandRange = new List<TimeBand>();
timeBandRange = TimeBandList.Where
(p => p.customerId == 1
&& p.DayName == date.DayOfWeek).ToList();
}
}