c# - 从方法返回 <list> 值

标签 c# asp.net entity-framework

我需要从我的 table 上获取特定患者的所有预约,为此我试过,

public List<Appoinment> GetAppoinments()         //here Appointment is a class.
    {
        List<Appoinment> appointments = null;

        foreach (DataObject.Appointment appointment in
                   dataEntities.Appointments.Where(a => a.PATIENTID == PatientId))
        {

        }

        return appointments;
    }

在我的约会类和表中,我有像 PatientId、doctorid、约会日期这样的字段,

在这里,在 foreach 循环中,我试过,

appointments.add(appointment);

它的thorwing错误,它不能自动从数据库表约会转换为类约会,对吧。

我不知道该怎么做,谁能帮我解决这个问题,在此先感谢

最佳答案

public List<Appointment> GetAppointments()      
{
    return dataEntities.Appointments
                       .Where(a => a.PATIENTID == PatientId)
                       .Select(a => new OtherNamespace.Appointment 
                                    {
                                        Id = a.Id,
                                        Name = a.Name,
                                        // etc.
                                    })
                       .ToList();
}

关于c# - 从方法返回 <list> 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11206452/

相关文章:

c# - 在 Entity Framework 核心中合并迁移

c# - 如何在带有 Entity Framework 的 ASp.net 应用程序中同时使用 MySQL 和 MSSQL

c# - EF : order by 2 fields when they are not null

c# - ResXFileCodeGenerator - 覆盖输出(想要使用自定义资源管理器)

c# - 是否有当前等效于停产的 "SQL Server English Query"

c# - 引用值 : string or integer?

asp.net - 如何为 ASP .NET 页面添加规范标签

c# - Active Directory - 获取多个广告组中的所有用户

在参数中调用时缺少 Javascript 斜杠

asp.net - 在 asp.net 页面中包含脚本的正确方法