简体   繁体   English

如何将 Sql 转换为 Linq C#

[英]How to Convert Sql to Linq C#

My Code Sql:我的代码 Sql:

declare @pFPId int ,@pDate datetime
select @pFPId =max(id) from __FiscalPeriod__
select @pDate =max(enddate) from __FiscalPeriod__

SELECT (select name from __StockRoom__ where FPId=@pFPId and id=1) as [نام انبار],[کد کالا], [نام کالا], [مقدار] ,
(SELECT Name FROM __Unit__ u WHERE u.Id = [واحد اصلي]  AND u.FPId = @pFPId ) AS [نام واحد اصلي] FROM __InventoryQ__(@pFPId, 1, @pDate, -1) WHERE [مقدار] > 0 
union all
SELECT (select name from __StockRoom__ where FPId=@pFPId and id=7) as [نام انبار],[کد کالا], [نام کالا], [مقدار] ,(SELECT Name FROM __Unit__ u WHERE u.Id = [واحد اصلي]  AND u.FPId = @pFPId ) AS [نام واحد اصلي] 
                   FROM __InventoryQ__(@pFPId, 7,@pDate, -1) WHERE [مقدار] > 0 

What is your suggestion?你的建议是什么?

You could look into using Linqer: http://www.sqltolinq.com/home您可以考虑使用 Linqer: http://www.sqltolinq.com/home

It converts SQL queries to linq and helps you to learn linq.它将 SQL 查询转换为 linq 并帮助您学习 linq。 It requires a connection string for your database so i am unable to show you the output for your above code.它需要您的数据库的连接字符串,因此我无法向您展示上述代码的 output。

There is also a great devblogs post going over conversions: https://devblogs.microsoft.com/vbteam/converting-sql-to-linq-part-1-the-basics-bill-horst/还有一篇很棒的开发博客文章讨论了转换: https://devblogs.microsoft.com/vbteam/converting-sql-to-linq-part-1-the-basics-bill-horst/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM