为了获得如下结果并显示按第 1 列分组的第 2 列(用户控件)和第 3 列(用户控件)。我编写了如下所示的代码,但速度很慢,实际上当我只使用第 1 列时,加载速度很快( 5 秒),当我使用第 1 列和第 2 列(用户控件“文档列表”)时,加载时间为 10 秒,当我使用第 1 列和第 2 列(文档列表”)和第 3 列(“DocTransList”)时,加载时间为 45 秒。我认为我在 LINQ 中的代码效率不高,但我不知道如何解决。
TRANSMITTAL No Documents REV
TT-001 DOC-001 01
DOC-002 01
public partial class Transmittals : System.Web.UI.Page
{
class TransmittalPresentationModel
{
public int TransID { get; set; }
public String TransmittalNo { get; set; }
public IEnumerable<tblDocument> Documents { get; set; }
public IEnumerable<tblTransmittall> DocTrans { get; set; }
}
private EDMSDataContext _DataContext;
protected void Page_Load(object sender, EventArgs e)
{
_DataContext = new EDMSDataContext();
if (!IsPostBack)
{
DisplayAuthors();
}
}
private void DisplayAuthors()
{
var query =
from transmittal in _DataContext.tbltransmittalNos
orderby transmittal.TRANSMITTAL
select new TransmittalPresentationModel
{
TransID = transmittal.TransID,
TransmittalNo = transmittal.TRANSMITTAL,
Documents = transmittal.tblTransmittalls.Select(Transmittals => Transmittals.tblDocument),
DocTrans = transmittal.tblTransmittalls
};
GridViewTransmittals.DataSource = query.ToList();
GridViewTransmittals.DataBind();
}
protected void GridViewTransmittals_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.DataItem == null) return;
TransmittalPresentationModel transmittal = (TransmittalPresentationModel)e.Row.DataItem;
DocumentList documentList = (DocumentList)e.Row.FindControl("DocumentList1");
DocTransList doctranslist = (DocTransList)e.Row.FindControl("DocTransList2");
documentList.Documents = transmittal.Documents;
documentList.DataBind();
doctranslist.DocTrans = transmittal.DocTrans;
doctranslist.DataBind();
}
}