Linq查询到SQL查询 [英] Linq query to SQL query

查看:64
本文介绍了Linq查询到SQL查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行良好的Linq查询但我需要编写SQL查询

任何人都可以帮我写吗?

我怎么能写这个和在sql命令中选择部分?



I have a Linq Query that works well but I need to write the SQL Query
Can Anybody help me write it?
How can i write the this where and select part in sql command?

ret = new List<RData>();

ret1 = (from a in View
        where
            a.LastRefreshTime>=Filter.From && a.LastRefreshTime<=Filter.To && a.ModelCode == mdlCode &&
            Filter.PN.Select(epn => epn.Substring(0, 11)).Contains(a.H) &&
            Filter.PN.Select(epn => epn.Substring(14, 2)).Contains(a.HV)

        select new RData
        {
            v = a.v,
            Date = a.LastRefreshTime,
            UserId = a.UserId,
            M = a.Name,
        }).Distinct().AsQueryable();
ret = ret1.Where(nr =>
    Filter.M == null || !Filter.M.Any() || Filter.M.Contains(nr.M)
).ToList();

推荐答案

您是唯一有权访问您要查询的数据表的人,因此它是其他人很难将LINQ翻译成SQL而没有机会尝试。



你最好自己学习如何做,并且有足够的资源在线,您可以找到示例。例如:

SQL WHERE子句 [ ^ ]



建立查询一步一步,直到你得到你想要的结果。



祝你好运。
You are the only one who has access to the data table you want to query, so it is difficult for anyone else to just translate LINQ to SQL with no chance to try it out.

It is better you learn how to do it yourself and there are plenty of resources online where you can find examples. For example:
SQL WHERE Clause[^]

Build up the query step by step until you have the result you want.

Good luck.


这篇关于Linq查询到SQL查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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