想象两个表:Shifts,RANK_S_DAY. Shifts包含一个DateTime的ShiftDate列,而RANK_S_DAY包含一个DayOfWeek列.我需要加入(int)ShiftDate.DayOfWeek equals DayOfWeek.我知道为什么它不起作用,但是我不太确定如何更改它.例外是:
Imagine two tables: Shifts, RANK_S_DAY. Shifts contains a ShiftDate column which is DateTime and RANK_S_DAY has a DayOfWeek column. I need to join (int)ShiftDate.DayOfWeek equals DayOfWeek. I understand why it won't work, but I'm not quite sure how I can change it. The Exception is:
LINQ to Entities不支持指定的类型成员'DayOfWeek'.仅支持初始化程序,实体成员和实体导航属性.
The specified type member 'DayOfWeek' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.
据我了解,LINQ无法将(int)ShiftDate.DayOfWeek转换为SQL可以理解的东西,有什么想法吗?
As I understand it, LINQ can't translate (int)ShiftDate.DayOfWeek to something SQL understands, Any ideas?
这是代码:
Shifts = from s in en.Shifts join j in en.RANK_S_JOB on s.kronos_JobPositions.JobID equals j.JOBNO join d in en.RANK_S_DAY on (int)s.ShiftDate.DayOFWeek equals d.DAY_OF_WEEK orderby d.RANK, j.RANK ascending select s;推荐答案
在这个级别上我无能为力.因此,我要做的是创建一个存储过程,该过程将两个表连接在一起并将其导入到Entity中,创建了一个函数导入,该函数返回了一个Shifts实体.不确定这是否是最好的方法,但它是否有效并且是否干净.
It appears there isn't anything I can do at this level. So what I've done is created a stored proc that joins the two tables and imported it into the Entity, created a function import that returned a Shifts entity. Not sure if thats the best approach, but it works and is clean.
更多推荐
LINQ to实体在DateTime.DayOfWeek上加入
发布评论