re3el re3el - 4 months ago 8
C# Question

Query enum value from DB in C#

My Appointment database has

Appointment ID, Status(enum type), Student
as column values.

This is the
Status
enum:

public enum StatusType
{
Pending,
Approved,
Cancelled
}


I need to query the list of rows in the db(appointments) where
Status
column is set to
'Pending'
and pass it to a list variable.

How do I do that in Visual Studio using C#?

IEnumerable<Appointment> AppQuery = from appointment in _appointmentData.GetAll()
where appointment.Status????
select appointment;


Note:
_appointmentData.GetAll()
lists the entire rows in the db.

Answer

Depends a bit on what gets stored in your database, but what about using .Equals:

IEnumerable<Appointment> AppQuery = from appointment in _appointmentData.GetAll()
       where appointment.Status.Equals(StatusType.Pending)
       select appointment;