0
私はいくつかの内容をリストしたページを持っています。以下のコードでページのページングを作成しました。しかし、私はRowCountを取得するために2番目のクエリを作成しなければならないことがわかります。データベースへの2回目のクエリなしでページングを実行できますか?Asp.net WebフォームとEntity Frameworkの単一のクエリでページング
// ContentList.aspx.cs
MySiteEntities db = new MySiteEntities();
my_ContentList = db.Content.Where(it => it.Language == "En" && it.Type == QueryType && it.Active == true && it.Deleted == false).OrderBy(it => it.Sort).Skip(PageSize * (PageIndex - 1)).Take(PageSize).ToList();
RowCount = db.Content.Where(it => it.Language == "En" && it.Type == QueryType && it.Active == true && it.Deleted == false).Count();
PageCount = RowCount/PageSize + 1;
// ContentList.aspx
<%if (RowCount > PageSize) {%>
<%if (PageIndex > 1) {%><a href="Content/<%=Type%>/<%=PageIndex-1%>" class="page-numbers prev">Previous</a><%}%>
<%
int Position = 1;
do
{
%>
<a href="Content/<%=Type%>/<%=Position%>" class="page-numbers <%if (Position == PageIndex) {%>current<%}%>"><%=Position%></a>
<%
Position++;
} while (Position < PageCount+1);
%>
<%if (PageIndex != PageCount) {%><a href="Content/<%=Type%>/<%=PageIndex+1%>" class="page-numbers next">Next</a><%}%>
<%}%>