简体   繁体   English

如何使用EF在asp.net core中使用存储过程

[英]how to use stored procedure in asp.net core using EF

I am working on an asp.net core application where I am using EF for database operations.我正在开发一个 asp.net 核心应用程序,我在其中使用 EF 进行数据库操作。 In some cases, I need to use Stored procedures.在某些情况下,我需要使用存储过程。 So when I tried to do so, I get errors.因此,当我尝试这样做时,出现错误。 The following is the code I used,以下是我使用的代码,

var result = await _context.Query<EmployeeResult>().FromSqlRaw("[usp_getEmployeedetails] @employeeID,@purpose", new SqlParameter("@employeeID", employeeID), new SqlParameter("@purpose", purpose)).ToListAsync(); 

Here the "EmployeeResult" is a ViewModel.这里的“EmployeeResult”是一个 ViewModel。 Inside the Sp, I am using multiple tables to create the result select query.在 Sp 内部,我使用多个表来创建结果选择查询。

The error message as follows "Cannot create a DbSet for 'EmployeeResult' because this type is not included in the model for the context."错误消息如下"Cannot create a DbSet for 'EmployeeResult' because this type is not included in the model for the context."

Can anyone help me to resolve the issue?谁能帮我解决这个问题?

将此代码添加到您dbcontext

public DbSet<EmployeeResult> EmployeeResults { get; set; }

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

相关问题 如何在EF核心和Asp.net核心中调用Stored Proc? - how to call Stored Proc in EF core and Asp.net core? 扩展我的 ASP.NET Core Web API (EF Core) 以调用存储过程 - Extend my ASP.NET Core Web API (EF Core) to call a stored procedure 使用 ASP.NET 核心和实体框架执行存储过程? - Execute stored procedure using ASP.NET Core and Entity Framework? 使用存储过程的 Asp.net 内核中的错误数据是 Null - Error Data is Null in Asp.net core using stored procedure 如何在 ASP.NET Core MVC 中使用 ADO.NET 将参数添加到存储过程? - How can I add parameters to a stored procedure using ADO.NET in ASP.NET Core MVC? 如何在 ASP.NET Core 3.0 的存储过程中添加参数 - How to add params in stored procedure in ASP.NET Core 3.0 如何使用 ZD7EFA19FBE7D3972FD5ADB6024Z2 在 ASP.NET Core 6 Web API 中运行存储过程? - How run stored procedure in ASP.NET Core 6 Web API using C#? 如何将EF6与ASP.NET Core 1结合使用 - How to use EF6 with ASP.NET Core 1 如何在ASP.NET中使用输出参数插入存储过程 - How to use the output parameter insert stored procedure in ASP.NET 在ASP.NET中使用数据访问层时如何在输出参数中使用存储过程 - How to use stored Procedure with output parameters while using Data Access layer with ASP.NET
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM