gpt4 book ai didi

c# - 错误 CS1061 : 'DbSet' does not contain a definition for 'FromSql' and no extension method 'FromSql' accepting a first argument of type 'DbSet'

转载 作者:行者123 更新时间:2023-11-30 16:40:35 26 4
gpt4 key购买 nike

我正在尝试在 mac os webapi 上使用 asp.net core 2.1 调用 View 或存储过程。

using System;
using System.Linq;
using Auth.Database;
using Microsoft.EntityFrameworkCore;

public virtual IQueryable<T> ExecuteStoreProcView(string viewProcName)
{
IQueryable<T> queryResult = _entities.Set<T>().FromSql(viewProcName).AsQueryable();
return queryResult;
}

出现以下错误

Error CS1061: 'DbSet' does not contain a definition for 'FromSql' and no extension method 'FromSql' accepting a first argument of type 'DbSet' could be found (are you missing a using directive or an assembly reference?) (CS1061)

我在 mac os 上使用 Entity Framework 开发 webapi。

研究以下链接中的一些查询:- Raw SQL Query without DbSet - Entity Framework Core

Raw SQL Query without DbSet - Entity Framework Core

https://forums.asp.net/t/1886501.aspx?System+Data+Entity+DbSet+Entities+User+does+not+contain+a+definition+for+FirstOrDefault+

https://learn.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.relationalqueryableextensions.fromsql?view=efcore-2.1

但找不到错误解决方案。谁能告诉我我缺少什么。

最佳答案

安装Microsoft.EntityFrameworkCore.Relational nuget包,然后在类中添加using语句

使用 Microsoft.EntityFrameworkCore;

关于c# - 错误 CS1061 : 'DbSet<T>' does not contain a definition for 'FromSql' and no extension method 'FromSql' accepting a first argument of type 'DbSet<T>' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51017703/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com