我有一个存储过程GetCountersByOutlet
,它返回几行
@Locale nvarchar(10),
@OutletID bigint,
@Take bigint,
@Skip bigint
WITH countersDetails AS
(
SELECT
CounterID, tto.Text as OutletTitle, ttc.Text as CounterTitle,
ROW_NUMBER() over (Order By CounterID) as RowNumber
FROM
Counters as c
INNER JOIN
Outlets as o ON c.OutletID = o.OutletID
INNER JOIN
TranslationTexts as ttc on c.TitleID=ttc.TranslationID
INNER JOIN
TranslationTexts as tto on o.TitleID=tto.TranslationID
WHERE
ttc.Locale = @Locale
AND tto.Locale = @Locale
AND o.OutletID = @OutletID
)
SELECT
CounterID, OutletTitle, CounterTitle, RowNumber
FROM
countersDetails
WHERE
RowNumber BETWEEN @Skip AND @Skip + @Take
现在我首先使用代码调用存储过程,如下所述
public static List<CounterDetail> GetCounterDetails(long outletID, long skip, long take, POSEntities context, string locale = "en-US")
{
SqlParameter localeParam = new SqlParameter("@Locale", locale);
SqlParameter outletIDParam = new SqlParameter("@OutletID", outletID);
SqlParameter skipParam = new SqlParameter("@Skip", skip);
SqlParameter takeParam = new SqlParameter("@Take", take);
return context.Database.SqlQuery<CounterDetail>("GetCountersByOutlet @Locale, @OutletID, @Skip, @Take", localeParam, outletIDParam, skipParam, takeParam).ToList();
}
CounterDetail
模型就是这样
public class CounterDetail
{
public Guid CounterID { get; set; }
public string OutletTitle { get; set; }
public string CounterTitle { get; set; }
public long RowNumber { get; set; }
}
但是在调用了这样的方法之后
var x = POSEntities.GetCounterDetails(8, 0, 10, context);
当我调用GetCounterDetails
方法时,我只获得一条记录,但是当在SQL Server上运行时,存储过程会返回多条记录。