【问题标题】:Query enum value from DB in C#在 C# 中从 DB 中查询枚举值
【发布时间】:2016-08-05 02:26:20
【问题描述】:

我的约会数据库有Appointment ID, Status(enum type), Student 作为列值。

这是Status 枚举:

 public enum StatusType
{
    Pending,
    Approved,
    Cancelled
}

我需要查询 db(appointments) 中 Status 列设置为 'Pending' 的行列表,并将其传递给列表变量。

如何在 Visual Studio 中使用 C# 做到这一点?

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

注意:_appointmentData.GetAll() 列出了数据库中的所有行。

【问题讨论】:

  • 你试过where appointment.Status == StatusType.Pending
  • 你的数据库中status的数据类型是什么?

标签: c# mysql enums


【解决方案1】:

取决于存储在数据库中的内容,但使用 .Equals 会怎样:

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

【讨论】:

    猜你喜欢
    • 2017-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-18
    • 2022-01-20
    • 2019-05-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多