【发布时间】:2017-10-15 07:13:52
【问题描述】:
鉴于此模型:
using X.Models;
namespace X.ViewModels
{
public struct YRow
{
public Y Y { get; set; }
public YContact LastPhoneCall { get; set; }
public YContact LastVisit { get; set; }
public YStatus LastStatus { get; set; }
}
}
我通过以下方式选择它:
public IQueryable<YRow> FetchData()
{
return db.Ys
.Select(x => new YRow
{
Y = x,
LastPhoneCall = x.Z
.Where(y => y.Type == YZType.PhoneCall)
.OrderBy(y => y.Date).LastOrDefault(),
LastVisit = x.Z
.Where(y => y.Type == YZType.Visit)
.OrderBy(y => y.Date).LastOrDefault(),
LastStatus = x.Statuses.OrderBy(y => y.Date).LastOrDefault(),
})
.OrderBy(x => x.Y.BusinessName);
}
传递给一个asp:GridView的SelectMethod:
<asp:GridView runat="server" SelectMethod="FetchData" ItemType="X.ViewModels.YRow">
...
</asp:GridView>
当我访问我得到的页面时:
方法 System.Web.UI.WebControls.QueryableHelpers.CountHelper:类型 参数“X.ViewModels.YRow”违反了类型参数的约束 'T'。
这是为什么呢?
【问题讨论】:
标签: c# asp.net entity-framework webforms