0

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;
Muhammad Akhtar
  • 51,913
  • 37
  • 138
  • 191
PKCS12
  • 407
  • 15
  • 41

2 Answers2

1

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.

Atzoya
  • 1,377
  • 13
  • 31
1

You have to add repeater content and bind...

    <asp:Repeater runat="server" ID="rptContents">
        <HeaderTemplate>
            <table width="100%" cellpadding="0" cellspacing="0">
        </HeaderTemplate>
        <ItemTemplate>
            <tr>
                <td>
                    <asp:Label ID="lblCont" runat="server" Text='<%#Eval("Contents") %>'></asp:Label>
                </td>
            </tr>
        </ItemTemplate>
        <FooterTemplate>
            </table>
        </FooterTemplate>
    </asp:Repeater>
Muhammad Akhtar
  • 51,913
  • 37
  • 138
  • 191