Ability to convert a LINQ query to a Stored Procedure, Trigger or View
Maybe this can already be done, but it would be great to write a LINQ Query then instead of just viewing the SQL the ability to view as a Trigger, View or Stored Procedure.
-
Anonymous commented
sp_helptext usp_BulkC
CREATE PROCEDURE [dbo].[usp_BulkCrudPurchaseDetail]
(
@param0 PurchaseOrderDetailTableType1 READONLY
,@param1 PurchaseOrderDetailTableType1 READONLY
,@param2 NVARCHAR(50) --CreatedBy
,@param3 INT -- PurchaseOrderID
,@param4 INT
)
AS
BEGIN
--Delete Record
UPDATE PurchaseOrderDetail SET IsActive=0,ModifiedBy=@param2,ModifiedDate=CAST(GETDATE() AS SMALLDATETIME)
FROM @param1 D JOIN PurchaseOrderDetail E ON E.ItemID=D.ItemID AND
E.PurchaseOrderID=@param3 AND 1=@param4--D.PurchaseOrderTypeID
--Enable already deleted Record
UPDATE PurchaseOrderDetail SET IsActive=1,
Quantity=D.Quantity,
Rate=D.Rate,
Amount=D.Amount,ModifiedBy=@param2,
ModifiedDate=CAST(GETDATE() AS SMALLDATETIME) FROM @param0 D JOIN
PurchaseOrderDetail E ON E.ItemID=D.ItemID AND E.PurchaseOrderID=@param3
AND 1=@param4--D.PurchaseOrderTypeID
MERGE PurchaseOrderDetail AS [Target]
USING @param0 AS [Source]
ON [Target].PurchaseOrderDetailID = [Source].PurchaseOrderDetailID
AND [Target].PurchaseOrderID = [Source].PurchaseOrderID
AND 1=@param4--[Source].PurchaseOrderTypeID
WHEN MATCHED THEN
UPDATE SET
ItemID=[Source].ItemID,
Quantity=[Source].Quantity,
Rate=[Source].Rate,
Amount=[Source].Amount
,ModifiedBy=@param2
,ModifiedDate = GETDATE()
WHEN NOT MATCHED AND (SELECT COUNT(PurchaseOrderDetailID) FROM PurchaseOrderDetail WHERE 1=[Source].PurchaseOrderTypeID
AND PurchaseOrderID=@param3 AND ItemID=[source].ItemID)<=0 THEN
INSERT (
PurchaseOrderID
,ItemID
,Quantity
,Rate
,Amount
,CreatedBy
,CreatedDate
)
VALUES (@param3,[Source].ItemID,[Source].Quantity,[Source].Rate,[Source].Amount,
@param2, GETDATE());
END rudPurchaseDetailconvert linq