将查询结果绑定到转发器
我是实体数据框架和 lambda 查询的新手。
我想做的是选择“联系人”列表并将其绑定到网格或中继器。
但是,尽管我的查询可以检索联系人记录,但我无法将其绑定到转发器。当我这样做时,它说“对象引用未设置到对象的实例”。
有人可以告诉我我做错了什么吗?
IQueryable<Contact> contactsQuery = from c in cc.Contacts
from g in c.ContactGroups
where g.GroupNameID == 1
select c;
MyRepeater.DataSource = contactsQuery;
MyRepeater.DataBind();
问题代码被抛出并在数据源规范行上:
MyRepeater.DataSource = contactsQuery;
I am new to the Entity Data framework and lambda query.
What I am trying to do is select a list of "contacts" and bind it to a grid or repeater.
However, although my query works in that it is able to retrieve contact records, I am unable to bind it to a repeater. When I do, it says "Object reference not set to an instance of an object".
Can someone please tell me what I am doing wrong?
IQueryable<Contact> contactsQuery = from c in cc.Contacts
from g in c.ContactGroups
where g.GroupNameID == 1
select c;
MyRepeater.DataSource = contactsQuery;
MyRepeater.DataBind();
The problem code is thrown and on the Datasource specification line:
MyRepeater.DataSource = contactsQuery;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
此异常是从 Contact 类中的某个位置引发的。尝试查看属性映射和可为空的属性,问题很可能就在那里。
This exception is thrown from somewhere inside your Contact class. Try looking at the property mappings and nullable properties, the problem is most likely there.
您必须添加转发器内容并绑定...
You have to add repeater content and bind...