views:

30

answers:

2

I have the following code:

var devices = from d in ctx.Devices.Include("DeviceGroups")
    where d.DeviceEnabled == true
    select d;
dlTerminals.DataSource = devices;

On the front end i do the following:

<asp:DataList ID="dlTerminals" runat="server" DataKeyField="DeviceId" GridLines="None" RepeatColumns="2" RepeatDirection="Horizontal" Width="100%">
    <ItemTemplate>
            <%# Eval("DeviceGroups.GroupName")%>
    </ItemTemplate>
</asp:DataList>

But i get the following error:

does not contain a property with the name 'GroupName'.

+1  A: 

Found a solution:

select new { d.DeviceId, d.MAC, d.DeviceType, d.LastConnectTime, d.DeviceGroups.FirstOrDefault().GroupName };
fARcRY
A: 

As you are developing asp.net flattening the data is probably the best solution. You may also consider adding a property to your class like

public string DeviceGroupName
{
    get
    {
        return this.DeviceGroups.FirstOrDefault();
    }

}
kubal5003