protected void BindDirctritInfo()
{
//获取小区ID
int disid = Convert.ToInt32(Request.QueryString["d"]);
var result = from s in ft.T_House_Distirct
join mt in ft.T_House_MoneyTrend on s.DistirctId equals mt.DorCId
where s.State == 0 && s.DistirctId == disid && mt.TrendType == 1
select new
{
s,
mt.AgeMoney
};
lbladdr.Text = result.First().s.Address;//异常详细信息: System.InvalidOperationException: 序列不包含任何元素
//获取物业名称
var wy = from s in ft.T_House_WType
join hwy in ft.T_House_WuYe on s.WuYeTpyeId equals hwy.WuYeTpyeId
join h in ft.T_House_Distirct on hwy.WuYeId equals h.WuYeId
where h.DistirctId == disid && h.State == 0
select new
{
s,
wygs = hwy.Name,
};
//数据绑定
lblWuYeType.Text = wy.First().s.Name;
lblOverTime.Text = Convert.ToString(result.First().s.OverTIme);
lblGreen.Text = Convert.ToString(result.First().s.Green) + "%";
var developer = ft.T_House_Developer.Where(o => o.DevelopersId == result.First().s.DevelopersId);
lbldeveloper.Text = developer.First().Name;
lblHouseCount.Text = Convert.ToString(result.First().s.Sumcount);
在方法最开始设个断点,单步调试一下,看看ID是否有值,看看生成的SQL语句能否在SQL Server里执行。
用FirstOrDefault或者Find。
First代表一定能找到,找不到就抛出异常