C# 使用带有Union的实体框架连接查询
我是C和EF的新手,我在一个包含多个查询的表中遇到了麻烦,我试图在一个网格中获取查询1和查询2中的所有字段,这些字段之间没有关系C# 使用带有Union的实体框架连接查询,c#,entity-framework,C#,Entity Framework,我是C和EF的新手,我在一个包含多个查询的表中遇到了麻烦,我试图在一个网格中获取查询1和查询2中的所有字段,这些字段之间没有关系 private class DataBindingProjection2 { public int ApmntID { get; set; } public int NId { get; set; } public int Emp { get; set; } public DateTime InT
private class DataBindingProjection2
{
public int ApmntID { get; set; }
public int NId { get; set; }
public int Emp { get; set; }
public DateTime InTime { get; set; }
public DateTime OutTime { get; set; }
public int price { get; set; }
}
Data.ODDBEntities2 We = new Data.ODDBEntities2();
string date = dateTimePicker1.Value.DayOfWeek.ToString();
var q3 = (from c in We.NonRegularDetails
where c.Date.Value == dateTimePicker1.Value
select new DataBindingProjection { ApmntID = c.ApmntID, NId = c.NID, Emp = c.Emp, InTime = c.InTime.Value, OutTime = c.OutTime.Value, price = 345 }).Union(from c in We.RegularAppDetails
where c.day == date
select new DataBindingProjection2 { ApmntID = (int)c.ApmntID, NId = c.RID, Emp = c.EmpId, InTime = c.InTime.Value, OutTime = c.OutTime.Value, price = 345 }).Select(c => new { c.ApmntID, c.NId, c.Emp, c.InTime, c.OutTime, price = 345 }).OrderBy(d =>d.ApmntID);
var users = q3.ToList();
我知道工会的错误是说
那么我做错了什么
有什么好方法可以做到这一点吗
这两个查询单独工作很好 检查您正在尝试将IQueryable与IQueryable合并,这是不可能的。现在还不清楚,为什么需要DataBindingProjection和DataBindingProjection2。您可以将投影设置为匿名类型,并将它们连接起来。@Sameer-它给出了相同的错误-我认为您这里的问题是类型不匹配:查询的类型为DataBindingProjection,q2的类型为DataBindingProjection2这就是union给出错误的原因。如果要联合组键,请选择组的键var q3=query.Selectx=>x.ApmntID.Unionq2.Selectx=>x.ApmntID@丹尼斯-好的,我试试tnx兄弟:D