什么是EF Core2.0中SqlQuery的替代品,我不想创建用于执行该过程的模型
var result = _context.Database.SqlQuery<string>("TWS_config_MidOfficeSystems_Validate @mo,@ga,@pcc,@xmo",
parameters: new SqlParameter[]
{ new SqlParameter("@mo",lineData),
new SqlParameter("@ga", gdsAccessId),
new SqlParameter("@pcc", crsPCC),
new SqlParameter("@xmo", bkMidOfficeCode),
}).FirstOrDefaultAsync();
class
。 public class ExampleClass
{
public string Name { get; set; }
public string Email { get; set; }
}
在ApplicationDbContext.cs
中将该类添加为DbQuery
public DbQuery<ExampleClass> ExampleClassDbQuery { get; set; }
将Dependency Injection
插入您的controller
或services
private readonly ApplicationDbContext _db; public ExampleService(ApplicationDbContext applicationDbContext) { _db = applicationDbContext; }
然后像下面这样调用strore过程
_db.ExampleClassDbQuery.FromSql("storeProcedureName", []parameters);