我在SQL Server上有一个表值函数
CREATE FUNCTION [dbo].[FStatusDepo]
(
@ProvozID int, @ZonaID int NULL, @minutesWarning int
)
RETURNS TABLE
AS
RETURN
(
SELECT
q.[DepoID]
,SUM(CASE WHEN v.Vjezd IS NOT NULL AND datediff(mi, v.Vjezd, GETDATE())>@minutesWarning THEN 1 ELSE 0 END) AS VjezduPoLhute
,SUM(CASE WHEN v.Vjezd IS NOT NULL AND datediff(mi, v.Vjezd, GETDATE())<=@minutesWarning THEN 1 ELSE 0 END) AS VjezduVLhute
FROM
...
我有一个新的项目与asp.net核心2.1和ef核心2.1。
I have read
我可以定义一个新的
Query
在dbcontext中键入:
public class StatusDepo
{
public int DepoID { get; set; }
public int VjezduPoLhute { get; set; }
public int VjezduVLhute { get; set; }
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder
.Query<StatusDepo>().ToView("FStatusDepo");
当我看这个例子时:
https://github.com/aspnet/EntityFrameworkCore/blob/dev/samples/QueryTypes/Program.cs
我看到了,我可能还应该将这一行添加到dbcontext:
public DbQuery<StatusDepo> StatusDepos { get; set; }
然后我就能执行:
using (DixieContext db = new DixieContext())
{
var listStatusDepo =
db.StatusDepos.FromSql("SELECT * FROM [dbo].[FStatusDepo] (1, 1, 20)").ToList();
}
这行得通,但是行:
modelBuilder.Query<StatusDepo>().ToView("FStatusDepo")
毫无意义,是否有其他参数化视图的构造,或者我应该删除该行并仅使用fromsql?