在.NET Core 3.1和EF Core中执行存储过程

时间:2020-09-01 13:45:10

标签: c# entity-framework-core

这是我的代码。对于FromSqlInterpolated,它可以正常运行,但存储过程不能运行imo。对于ExecuteSqlCommand,它运行时在@p0上有语法错误

        var a = "abc";
        var b = 10;
        var result = _dataContext.FileFolders.FromSqlInterpolated($"EXECUTE dbo.AddFileFolderStructure {10} {a} {a}");

       // _dataContext.Database
           .ExecuteSqlCommand("dbo.AddFileFolderStructure @p0 @p1 @p2", b, a, a);

        _dataContext.SaveChanges();

我也在下面尝试过

        var id = new SqlParameter("id", 10);
        var folderName = new SqlParameter("folderName", "1");
        var folderType = new SqlParameter("folderType", "5");
        var result = _dataContext.FileFolders.FromSqlRaw($"EXECUTE dbo.AddFileFolderStructure {id} {folderName} {folderType}");

        _dataContext.SaveChanges();

0 个答案:

没有答案