【问题标题】:Stored Procedures for non entity objects with ef core 6使用 ef core 6 的非实体对象的存储过程
【发布时间】:2023-02-11 00:24:49
【问题描述】:

我有一个 .net 6 ef core 6.0.7 项目。

我需要调用一个存储过程,该过程返回一个在数据库中没有等效对象的 DTO,以便在 DbSet 上调用它。

我发现一些文章说 SqlQuery 或 ExecuteRawSql 都是从 DbContext.Database 调用的,但我无法连接这些点。

    public class ProcedureRepository
    {
        private DatabaseContext databaseContext;

        public ProcedureRepository(DatabaseContext databaseContext)
        {
            this.databaseContext = databaseContext;
        }

        public Task<OrderDTO> GetOrders()
        {
            databaseContext.Database.ExecuteSqlCommand<OrderDTO>();
            databaseContext.Database.SqlQuery<OrderDTO>();

            /both line throw error saying:
            /"DatabaseFacade does not containt a definition for ..." 
        }
    }

【问题讨论】:

  • 只需使用 EF Core Power Tools - 它会为你连接点

标签: c# entity-framework-core


【解决方案1】:

我有同样的问题,没有更新吗?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-04-14
    • 2016-03-19
    • 1970-01-01
    • 2021-04-27
    • 1970-01-01
    • 1970-01-01
    • 2022-06-11
    相关资源
    最近更新 更多