错误CS1061:"DbSet< T>"不包含'FromSql'的定义,也没有扩展方法'FromSql'接受类型为'DbSet< T>'的第一个参数 [英] Error CS1061: 'DbSet<T>' does not contain a definition for 'FromSql' and no extension method 'FromSql' accepting a first argument of type 'DbSet<T>'

查看:189
本文介绍了错误CS1061:"DbSet< T>"不包含'FromSql'的定义,也没有扩展方法'FromSql'接受类型为'DbSet< T>'的第一个参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Mac OS Webapi上使用 asp.net core 2.1 调用视图或存储过程.

I am trying to call view or store procedure using asp.net core 2.1 on mac os webapi.

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;
}

出现以下错误

错误CS1061:"DbSet"不包含"FromSql"的定义并且没有扩展方法'FromSql'接受类型的第一个参数可以找到"DbSet"(您是否缺少using指令或组装参考?)(CS1061)

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上的实体框架开发webapi.

I am developing webapi using entity framework on mac os.

在下面的链接中搜索一些查询:-没有DbSet的原始SQL查询-实体框架核心

Research some of the queries in below link :- Raw SQL Query without DbSet - Entity Framework Core

没有DbSet的原始SQL查询-实体框架核心

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

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

但找不到错误解决方案.谁能让我知道我在想什么.

But not able to find the error solution. Can anyone please let me know what I, am missing.

推荐答案

自Umer回答以来,这可能已更改.现在,它位于 Microsoft.EntityFrameworkCore 命名空间中.但是您需要参考该程序包.

This might have changed since Umer answered. It is now in the Microsoft.EntityFrameworkCore namespace. But you will need to reference the package.

所以...

dotnet add package Microsoft.EntityFrameworkCore.Relational

并添加此行...

using Microsoft.EntityFrameworkCore;

这篇关于错误CS1061:"DbSet&lt; T&gt;"不包含'FromSql'的定义,也没有扩展方法'FromSql'接受类型为'DbSet&lt; T&gt;'的第一个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆