LINQ to实体在DateTime.DayOfWeek上加入

编程入门 行业动态 更新时间:2024-10-23 20:30:19
本文介绍了LINQ to实体在DateTime.DayOfWeek上加入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

想象两个表: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上加入

本文发布于:2023-06-03 10:04:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/473753.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:实体   LINQ   DayOfWeek   DateTime

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!