我想使用代码优先导入存储过程,该代码是从SQL Server创建的。我试图检查发布的文章,但似乎找不到到目前为止我了解的东西。下面的SQL语句是3个表的联接,因此,如果我可以使用下面的示例代码来获得如何解决该问题的示例。
USE [lifestyle]
GO
/****** Object: StoredProcedure [dbo].[ReportMasterDetail] Script Date: 2019/10/27 08:32:43
******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[InvoiceReport]
AS
SELECT
Ordering.order_id,
Ordering.CustomerId,
Ordering.invoice_number,
Ordering.date_order_placed,
Customer.FirstName,
Customer.LastName,
Customer.EmailId,
Invoice_Line_Items.item,
Invoice_Line_Items.department,
Invoice_Line_Items.service,
Invoice_Line_Items.gender,
Invoice_Line_Items.quantity,
Invoice_Line_Items.price,
Invoice_Line_Items.pick_up_address,
Invoice_Line_Items.pick_up_date,
Invoice_Line_Items.pick_up_time,
Invoice_Line_Items.drop_off_address,
Invoice_Line_Items.drop_off_date,
Invoice_Line_Items.drop_off_time
FROM Ordering join Customer ON Ordering.CustId = Customer.CustId
join Invoice_Line_Items ON Customer.CustId = Invoice_Line_Items.CustId
RETURN 0
我通常以以下方式使用存储过程:
Sql()
进行的迁移中>示例迁移:
public partial class yourmigration: Migration { protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.Sql("CREATE PROCEDURE SQL HERE"); } //dont forget the down. }
对于EF 6,这是一篇很好的文章:https://www.entityframeworktutorial.net/entityframework6/code-first-insert-update-delete-stored-procedure-mapping.aspx