开发者

Silverlight 4 RIA Services - select first entity from EntitySet

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:

开发者_如何学Python
//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


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??)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜