ZeroToHero
ZeroToHero

Reputation: 64

How to Convert Sql to Linq C#

My Code 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?

Upvotes: 0

Views: 233

Answers (1)

SilentUK
SilentUK

Reputation: 195

You could look into using Linqer: http://www.sqltolinq.com/home

It converts SQL queries to linq and helps you to learn linq. It requires a connection string for your database so i am unable to show you the output for your above code.

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/

Upvotes: 1

Related Questions