我有以下查询:
dat =
from s in dat
orderby s.Schedule.Employee.EmployeName ascending
select s;
问题是Schedule
或Employee
可能是null
,在这些情况下,它应该只显示第一个或最后一个,我不在乎。
有没有办法做到这一点?目前它在null
.
用于对网格视图进行排序:
[NullReferenceException: Object reference not set to an instance of an object.]
KezberProjectManager.Cases.<gvCases_Sorting>b__8(Case s) in C:\Users\jlarouche\documents\visual studio 2010\Projects\KezberProjectManager\KezberProjectManager\Cases.aspx.cs:103
System.Linq.EnumerableSorter`2.ComputeKeys(TElement[] elements, Int32 count) +88
System.Linq.EnumerableSorter`1.Sort(TElement[] elements, Int32 count) +21
System.Linq.<GetEnumerator>d__0.MoveNext() +178
System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding) +1698
System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +67
System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable data) +14
System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +123
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +33
System.Web.UI.WebControls.DataBoundControl.PerformSelect() +138
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +30
System.Web.UI.WebControls.GridView.DataBind() +4
KezberProjectManager.Cases.gvCases_Sorting(Object sender, GridViewSortEventArgs e) in C:\Users\jlarouche\documents\visual studio 2010\Projects\KezberProjectManager\KezberProjectManager\Cases.aspx.cs:138
System.Web.UI.WebControls.GridView.OnSorting(GridViewSortEventArgs e) +122
System.Web.UI.WebControls.GridView.HandleSort(String sortExpression, SortDirection sortDirection) +65
System.Web.UI.WebControls.GridView.HandleSort(String sortExpression) +78
System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +497
System.Web.UI.WebControls.GridView.RaisePostBackEvent(String eventArgument) +205
System.Web.UI.WebControls.GridView.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +9642898
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724