如何将sql查询转换为linq查询? [英] How to convert sql query to linq query?

查看:86
本文介绍了如何将sql查询转换为linq查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



linq查询无法读取getdate()sql函数,因为它输出以下错误 - 名称'getdate '在当前上下文中不存在



更新了Linq查询:

Hello,

The linq query is unable to read the "getdate()" sql function, as it outputs the following error -- "The name 'getdate' does not exist in the current context"

Updated Linq query:

public string getSubs(string username)
        public string getSubs(string username)
        {

            var query = from s in db.Subscriptions
                        join u in db.UserDetails on s.sUID equals u.uID
                        where s.sPriceABS_ExpiryDate >= DateTime.Now &&
                        s.sPID.Value == 163 &&
                        u.uUsername == username
                        select query;
         }

       }





有没有办法让linq读取getdate( )sql函数?非常感谢



Is there a way to get linq to read the "getdate()" sql function? Many thanks

推荐答案

你可以使用我描述的技术这里 [ ^ ]这样做。请确保完全按照说明进行操作。
You can use the technique I describe here[^] to do this. Make sure you follow the instructions exactly.


使用母语日期和时间类来获取日期

use native language date and time class to get date
public string getSubs(string username)
        {
            var query = from s in db.Subscriptions
                        join u in db.UserDetails on s.sUID equals u.uID
                        where s.sPriceABS_ExpiryDate >= DateTime.Now &&
                        s.sPID = "163"
                        select new
                        {
                            u.uID,
                            u.uUsername,
                            u.uPassword,
                            s.sPriceABS_ExpiryDate
                        };

       }


这样可以正常使用。它与语法错误有关。使用正确的语法来编写查询

This will work fine. it is related to syntax error. Use proper syntax to write query
public string getSubs(string username)
        {
            var query = from s in db.Subscriptions
                        join u in db.UserDetails on s.sUID equals u.uID
                        where s.sPriceABS_ExpiryDate >= DateTime.Now &&
                        s.sPID == "163"
                        select new
                        {
                            u.uID,
                            u.uUsername,
                            u.uPassword,
                            s.sPriceABS_ExpiryDate
                        };

       }


这篇关于如何将sql查询转换为linq查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆