Не могу понять в чем у меня проблема
contacts.aspx
<asp:Repeater ID="ReapeterContacts" runat="server" >
<HeaderTemplate>
<table id="contact" class="table-bordered">
<thead>
<tr>
<th>ФИО</th>
<th>Компания</th>
</tr>
</thead>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<b>
<%# Eval("firstname")%></b>
</td>
<td>
<%# Eval("company")%></b>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
contacts.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindTable();
}
}
protected void BindTable()
{
using (contactsEntities db = new contactsEntities())
{
ReapeterContacts.DataSource = from p in db.persons
join ph in db.phones on p.id equals ph.person_id into ljoin1
from phone in ljoin1.DefaultIfEmpty()
join e in db.emails on p.id equals e.person_id into ljoin2
from mail in ljoin2.DefaultIfEmpty()
select new
{
firstname = p.firstname,
company = p.company
};
ReapeterContacts.DataBind();
}
Выдает ошибку:
Additional information: Data binding directly to a store query (DbSet, DbQuery, DbSqlQuery, DbRawSqlQuery) is not supported. Instead populate a DbSet with data, for example by calling Load on the DbSet, and then bind to
Я вроде и вот так сделал
ReapeterContacts.DataSource = (from p in db.persons
join ph in db.phones on p.id equals ph.person_id into ljoin1
from phone in ljoin1.DefaultIfEmpty()
join e in db.emails on p.id equals e.person_id into ljoin2
from mail in ljoin2.DefaultIfEmpty()
select new
{
firstname = p.firstname,
company = p.company
}).ToList();
Но ничего не помогает. Как мне в таблицу вывести данные из базы? Где я не прав?