views:

51

answers:

1

I have a WPF application consuming data using Entity Framework 4 and Self-Tracking Entities. In which I have a window with 2 controls in it, one that shows the "Details" portion of an object using a ContentControl and templates from a merged resource dictionary. Another with a ListBox of Groups the object in question belongs to and a ComboBox of available groups it could belong towith a button wired up via a command to the control to add/remove items from the bound collection of Groups based on the SelectedItem of the ComboBox. All this is bound together by DependencyPropertys.

In my Window I have DP's for the Object, EditedItem we are editing and a read only property with a List of Group of the groups it could belong to and bind that to my controls via XAML.

SO....

If I create a new instance of one of my entities, set it's properties like so: (Really this is the exact code)

        Employee employee = Context.CreateObject<Employee>();
        employee.Name = "Joe Nobody's Brother Steve";
        employee.Active = true;
        employee.Username = "snobody";

        Group group = Context.CreateObject<Group>();
        group.Name = "Losers";
        group.DisplayName = "Spirit Squad";

        employee.Groups.Add(group);

And set it as my Window's EditedItem it works FLAWLESSLY!

If I however fetch this exact same entity from my Database the Groups ListBox is empty. Any ideas?

A: 

It turns out I had made a mistake else where: I needed to call:

    ObjectContext.LoadProperty(entity, navigationProperty);

on my navigation properties for them to get populated. I think this has something to do with my objects all being derived from a core object and the fact that I select them using OfType on the ObjectSet of the core object. Or it could be behavior but I would think I would have encountered it before now.

But hey I'll take working, and this is easy enough to integrate into my selection methods and properties.

Chalk this one up to ignorance of EF4.

Nick Daniels