How to return IEnumerable with NewUnitPhaseStatus as an enum?
In SQL the value "NewUnitPhaseStatus" is stored as an int. If I just return the query, then when I try to extract the value it just says that the DBcontext has been disposed. But If I try to convert the query result into a list, then it says that int cannot be converted to type NewUnitPhaseStatus(the enum type).
public IEnumerable<UnitPhaseLog> GetAllForUnitPhase(long unitPhaseId)
{
using (var db = new DbContext(_connStringKey))
{
var querys = from s in db.UnitPhaseLogs
where s.UnitPhaseId == unitPhaseId
select s;
return querys;
}
}
If one uses a foreach statement to convert each row into an enum, they get an error because var query is of class UnitPhaseLog with NewUnitPhaseStatus equal to enum.
Error message:
If one tries to convert the results to a list.
The 'NewUnitPhaseStatus' property on 'UnitPhaseLog' could not be set to a 'System.Int64' value. You must set this property to a non-null value of type 'Core.UnitPhaseStatus'.
If one tries to just return the query results themselves:
The operation cannot be completed because the DbContext has been disposed.
Code:
public enum UnitPhaseStatus
{
[Display(Name = "No Status")]
NoStatus,
[Display(Name = "Not Ready")]
NotReady,
[Display(Name = "Materials Needed")]
MaterialsNeeded,
[Display(Name = "Ready For Work")]
ReadyForWork,
[Display(Name = "Work In Progress")]
WorkInProgress,
[Display(Name = "Ready")]
ReadyForQc,
[Display(Name = "Approved")]
Approved,
[Display(Name = "Rejected")]
Rejected,
}
UnitPhaseStatus UnitPhaseStatus = query.NewUnitPhaseStatus;querys?