使用Entity FrameWork和Union加入查询

时间:2014-01-27 06:16:20

标签: 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 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(); 

我在工会中说错误

enter image description here

所以我做错了什么?

还有一种很好的方法吗?

这两个查询单独工作很好!!

0 个答案:

没有答案