C# 使用linq查询比较列与列
我遇到了一个我目前一直在解决的问题。例如:C# 使用linq查询比较列与列,c#,linq,linq-to-entities,C#,Linq,Linq To Entities,我遇到了一个我目前一直在解决的问题。例如: EmployeeShiftID | ShiftTime_Start | hiftTime_Stop | Name | Emp_Start | Emp_Stop |(linked with foreign key)| (linked with FK) | | | 1 | 0000
EmployeeShiftID | ShiftTime_Start | hiftTime_Stop | Name | Emp_Start | Emp_Stop
|(linked with foreign key)| (linked with FK) | | |
1 | 0000 | 1000 | Ken | 0000 | 1000
这些数据显示在数据网格视图中,外键链接。换档启动和停止也与Emp_启动和停止相匹配。问题是,当我更新Emp_启动和停止时,换档时间_启动和停止与Emp_启动和停止不相比较,并在我尝试将Emp_启动和停止更改为0430和2100时保持为0000和1000
我在数据库中保存的时间类型是String而不是time。有人能帮我吗?我将展示我为它所做的任何代码
private void btnUpdate_Click(object sender, EventArgs e)
{
using (testEntities Setupctx = new testEntities())
{
int ID = Int32.Parse(lblID.Text);
var ESquery = (from es in Setupctx.employeeshifts
where es.EmployeeShiftID == ID
select es).First();
ESquery.StartTime = txtStart.Text;
ESquery.EndTime = txtStop.Text;
ESquery.Date = txtDate.Text;
Setupctx.SaveChanges();
txtStart.Text = "";
txtStop.Text = "";
txtDate.Text = "";
this.Edit_Employee_Shift_Load(null, EventArgs.Empty);
MessageBox.Show("Employee's Shift Has Been Updated.");
}
}
private void LoadAllEditEmpShift()
{
using (testEntities Setupctx = new testEntities())
{
BindingSource BS = new BindingSource();
var Viewemp = from ES in Setupctx.employeeshifts
join shifthour sh in Setupctx.shifthours on ES.ShiftHourID equals sh.idShiftHours
select new
{
ES.EmployeeShiftID,
ShiftHour_Start = sh.shiftTiming_start,
ShiftHour_Stop = sh.shiftTiming_stop,
ES.EmployeeName,
ES.StartTime,
ES.EndTime,
ES.Date
};
BS.DataSource = Viewemp;
dgvEmpShift.DataSource = BS;
}
}
您应该在btnUpdate\u Click方法中隐式更新shifthour对象的属性。我认为它应该如下所示:
private void btnUpdate_Click(object sender, EventArgs e)
{
using (testEntities Setupctx = new testEntities())
{
int ID = Int32.Parse(lblID.Text);
var ESquery = (from es in Setupctx.employeeshifts
where es.EmployeeShiftID == ID
select es).First();
var SHquery = (from sh in Setupctx.shifthours where sh.idShiftHours == ESQuery.ShiftHourID
select sh).First();
ESquery.StartTime = txtStart.Text;
ESquery.EndTime = txtStop.Text;
ESquery.Date = txtDate.Text;
SHquery.shiftTiming_start = ESquery.StartTime;
SHquery.shiftTiming_stop = ESquery.EndTime;
Setupctx.SaveChanges();
txtStart.Text = "";
txtStop.Text = "";
txtDate.Text = "";
this.Edit_Employee_Shift_Load(null, EventArgs.Empty);
MessageBox.Show("Employee's Shift Has Been Updated.");
}
}
能给我举几个例子吗?