简体   繁体   English

使用 EF Core 7 调用存储过程

[英]Calling Stored Procedure using EF Core 7

Using the recently released EF Core 7, I have seen in Code magazine that you can map to stored procedures as follows (for example):使用最近发布的 EF Core 7,我在 Code 杂志上看到你可以 map 到存储过程如下(例如):

modelBuilder.Entity<Person>()
    .InsertUsingStoredProcedure("PeopleInsert",
        spbuilder => spbuilder
            .HasParameter(p => p.FirstName)
            .HasParameter(p => p.LastName)
)

But what is the C# syntax for calling the stored procedure once it is mapped in this way?但是一旦以这种方式映射,调用存储过程的 C# 语法是什么?

I can of course call the stored procedure using FromSqlRaw as previously but I thought that the mapping would lead to a more elegant way of calling it, which I have as yet been unable to establish.我当然可以像以前一样使用 FromSqlRaw 调用存储过程,但我认为映射会导致调用它的更优雅的方式,我还无法建立这种方式。

Your stored procedure will be called when you INSERT a new item (triggered by the database context).当您插入一个新项目(由数据库上下文触发)时,将调用您的存储过程。 Similar setups are available for DELETE and UPDATE.类似的设置可用于删除和更新。

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

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