我试着给病人摆桌子。我使用 entityframework 从数据库中提取数据。但我想让性别数据为男性,如果为真,则为女性,如果为假
aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DentistAppointmentSystem.Entity;
namespace DentistAppointmentSystem.AdminPages
{
public partial class DPatients : System.Web.UI.Page
{
DentistAppointmentSystemEntities db = new DentistAppointmentSystemEntities();
protected void Page_Load(object sender, EventArgs e)
{
var hastalar = (from x in db.TBL_PATIENTS
select new
{
x.TBL_USERS.Name,
x.TBL_USERS.Surname,
x.IDNumber,
x.Gender,
x.Birthday,
x.Phone
}).ToList();
Repeater1.DataSource = hastalar;
Repeater1.DataBind();
}
}
}
我使用实体框架从数据库中提取数据。但我想让性别数据为男性,如果为真,则为女性,如果为假
您可以在您的匿名投影中进行此更改。
var hastalar = (from x in db.TBL_PATIENTS
select new
{
x.TBL_USERS.Name,
x.TBL_USERS.Surname,
x.IDNumber,
Gender = x.Gender ? "Male" : "Female",
x.Birthday,
x.Phone
}).ToList();
你也可以做一个功能:
public string GetGender(bool gender)
{
if (gender)
{
return "Male";
}
else
{
return "Female";
}
}
然后这样称呼它:
x.Gender = GetGender(x.Gender)