【发布时间】:2015-07-22 18:30:15
【问题描述】:
我正在尝试使用从 LinqToSQL 语句中检索到的项目列表填充数据网格,这让我有些困惑。
当我明确地将 where 子句设置为等于硬编码的整数时,返回的列表没有任何问题。但是,当我使用具有包含相同整数的属性的对象时,将返回列表但不会填充数据网格。
返回的列表有,我假设私有和公共属性。硬编码的整数返回列表包含所有属性,而具有属性返回列表的对象仅包含私有属性,而公共属性声明“函数评估已禁用,因为先前的函数评估超时”
Example:
object.country _countryid _continentid _countryname CountryID ContinentID CountryName
这是两个 LinqToSQL 语句(都返回一个项目列表,但只有一个没有抛出错误):
工作 LinqToSQL 语句
protected void rgcountry_NeedDataSource(object sender, EventArgs e)
{
List<db_entity.country> _clist;
using (db_era.era_entities _ee = new db_era.era_entities())
{
_clist = (from a in _ee.countries where a.ContinentID == 4 select a).ToList();
}
if (_clist.Count > 0)
this.rgcountry.DataSource = _clist;
else
this.rgcountry.DataSource = empty();
}
非工作 LinqToSQL 语句 - (设置了continentselected 并且continentID 确实有值)
protected void rgcountry_NeedDataSource(object sender, EventArgs e)
{
List<db_entity.country> _clist;
if (continentselected != null)
{
using (db_era.era_entities _ee = new db_era.era_entities())
{
_clist = (from a in _ee.countries where a.ContinentID == continentselected.ContinentID select a).ToList();
}
if (_clist.Count > 0)
this.rgcountry.DataSource = _clist;
else
this.rgcountry.DataSource = empty();
}
else
this.rgcountry.DataSource = empty();
}
我在这里缺少什么?或者这就是 LinqToSQL 的工作方式?
【问题讨论】:
-
ContinentID getter 中有什么逻辑吗?我也没有看到对数据绑定的调用...
-
您确定continentselected.ContinentID 实际上具有有效值吗?因为它是整数,所以默认为 0。你确定它设置为 4 吗?
-
@Stephen Panzer:对于 Telerik RadGrid,您不需要数据绑定。 ContinentID getter 到底是什么意思?
-
@neo:是的,我是肯定的continentselected。ContinentID 确实有一个有效值。范围从 1 到 7,因为我们的数据库中有 7 个大陆。 And the continentselected is set when another datagrid item is selected.这一点我很确定。
-
@mattgcon:我使用 devexpress 网格进行此类查询没有问题。大陆选择和大陆选择.ContinentID的类型是什么?
标签: c# asp.net linq-to-sql