连接表多个条件 - 比较日期 - Linq
我试图根据多个条件对两个表进行联接,问题是我无法比较日期字段。日期以日期时间格式存储在数据库中,我想要特定日期的所有记录,当我按照下面的代码所示执行此操作时,我收到此异常..方法“System.String ToShortDateString()”不支持翻译成SQL。
PS这是一个大查询的一部分..
string dt = "10/14/2009";
using (ReportGeneratorDataContext db = new ReportGeneratorDataContext())
{
var r = from f in db.f
join a in db.a
on new { x = f.ID, y = f.date.ToShortDateString() } equals new { x = a.ID, y = dt }
select f.Name;
}
有什么解决方法吗?
I'm trying to do a join on two tables based on multiple conditions, the problem is I'm not able to compare the date fields. The date is stored in datetime format in DB and I want all the records on a particular date, when I do this in as shown in the code below, I get this exception .. Method 'System.String ToShortDateString()' has no supported translation to SQL.
P.S this is part of a big query..
string dt = "10/14/2009";
using (ReportGeneratorDataContext db = new ReportGeneratorDataContext())
{
var r = from f in db.f
join a in db.a
on new { x = f.ID, y = f.date.ToShortDateString() } equals new { x = a.ID, y = dt }
select f.Name;
}
Any workarounds?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会尝试
a
的计算列(在表中或在视图中),其中包含转换为日期的字符串(在数据库端...)where
)我知道,这些选项都不是真正令人满意的,但是我想这是 Linq-To-Sql 的一个缺点......
I would try to
a
which contains the string converted to a date (on DB side ...)where
on this enumeration)I am aware, that none of these options is really satisfying, but I suppose that's a shorcoming of Linq-To-Sql...