views:

161

answers:

1

Hi, I'm working with Silverlight 4 on getting a single entity from an Entity Set. Doesn't sound hard?! Well, I simply can't get it working:

myDomainContext dc = new OrgUnitTestDomainContext();
OrgUnit ou;
ou=dc.OrgUnits[0]; //Error 1    The property or indexer 'System.ServiceModel.DomainServices.Client.EntitySet.List' cannot be used in this context because the get accessor is inaccessible
ou=dc.OrgUnits.First; //Error   2   ... does not contain a definition for 'First' and no extension method 'First' accepting a first argument
ou=dc.OrgUnits.Current; //Error 3   ... does not contain a definition for 'Current' and no extension method 'Current' accepting a first argument
ou=dc.OrgUnits.List.First; //Error  4   The property or indexer 'System.ServiceModel.DomainServices.Client.EntitySet.List' cannot be used in this context because the get accessor is inaccessible
ou=dc.OrgUnits.List.Current; //as Error 3

Don't I see the forest because of the trees, or do I really have to do ugly things like:

//That works
System.Collections.Generic.IEnumerator<OrgUnit> enu = dc.OrgUnits.GetEnumerator();
enu.MoveNext();
ou = enu.Current;

//That works, but its ugly, too
foreach (OrgUnit ou in dc.OrgUnits)
{
    SelectedOrgUnit = ou;
    break;
}

Has anyone an idea what's wrong there - as said, I'm only trying to get a single entity? Best Regards, rwh

A: 

You haven't loaded any data into your DomainContext. It is empty until you load the data you require. (Unless you have done so in your XAML??)

Ardman
Hi, thanks for the hint. Actually, the declarationmyDomainContext dc = new OrgUnitTestDomainContext();is elsewhere, I just copied it in to clarify the meaning of dc. All other lines are in OnOrgUnitsLoaded, the method that's called as soon as the load is completed. The error messages shown in the comment are shown at designtime, already, so I guess there's another way to do it?
rwh