开发者

Silverlight RIA request only returns 1

I have the following code...

internal sealed class Menu_Metadata
{
    private Menu_Metadata() { }

    [Key]
    public int MenuHeaderID { get; set; }
    public string MenuHeaderName { get; set; }
    [Include]
    [Association("MenuHeader_MenuItem", "MenuHeaderID", "MenuHeaderID")]
    public IEnumerable<MenuItem> MenuItems { get; set; }
}
开发者_StackOverflow中文版
public class EmployeeMenuItem
{
    [Key]
    public int MenuItemID { get; set; }
    public int MenuHeaderID { get; set; }
    public string MenuItemName { get; set; }
}

[MetadataType(typeof(Menu_Metadata))]
public class EmployeeMenu
{
    public int MenuHeaderID { get; set; }
    public string MenuHeaderName { get; set; }
    public IEnumerable<EmployeeMenuItem> MenuItems { get; set; }
}

[EnableClientAccess()]
public class EmployeeMenuService : DomainService
{
    public IQueryable<EmployeeMenu> GetEmployeeMenu()
    {
        BusinessLogic.Employee blEmployee = new BusinessLogic.Employee();

        int employeeId = blEmployee.GetEmployeeIdFromUserName(HttpContext.Current.User.Identity.Name);
        var menuHeaders = blEmployee.GetEmployeeMenuHeaders(employeeId);
        // This works here!

        IQueryable<EmployeeMenu> retValue = from mh in menuHeaders
                                            select new EmployeeMenu
                                            {
                                                MenuHeaderID = mh.ID,
                                                MenuHeaderName = mh.HeaderName,
                                                MenuItems = from mhi in mh.MenuHeaderItems
                                                            select new EmployeeMenuItem 
                                                            { 
                                                                MenuItemID = mhi.MenuItemID,
                                                                MenuHeaderID = mhi.MenuHeaderID,
                                                                MenuItemName = mhi.MenuItem.MenuItemName 
                                                            }
                                            };
        return retValue;
    }
}

which is consumed by a Silverlight Accordion control

EmployeeMenuContext employeeMenuContext = new EmployeeMenuContext();
accordion2.ItemsSource = employeeMenuContext.EmployeeMenus;
employeeMenuContext.Load(employeeMenuContext.GetEmployeeMenuQuery());

The MenuHeaderName's are coming through just fine, and the MenuItems is populated for the 1st MenuHeader, but the other 3 MenuItems are empty.

Any ideas why?

At what point is it easier to use EF4 and RIA??? This seems so incredibly and needlessly complex to get a simple Entity with a sub-class in it!


I'm not entirely sure, but it appears that the problem may have been that I was trying to databind in the xaml constructor. I created a Loaded event and moved the code there and it seems to work now.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜