开发者

Retrieval of Single Entity + Ria Services

I am reading and doing some RnD on RIA as a solution for a new Silverlight project.

I have read alot of the documentation and decided to do a small mockup of a system using .Net RIA Services.

I want to know how to get a Single Entity from the Domain Service?

example: I want to get a person and populate a form:

 public Person GetSinglePerson()
        {
            return new Person { ID = 4, FirstName = "Cyanide", LastName = "Happiness", Status=3 };

} Say I use the the DomainDataSource:

&l开发者_运维知识库t;riaControls:DomainDataSource x:Name="source2" QueryName="GetSinglePersonQuery" AutoLoad="True">
                    <riaControls:DomainDataSource.DomainContext>
                        <web:DataContext/>
                    </riaControls:DomainDataSource.DomainContext>
                </riaControls:DomainDataSource>

This only returns a EntityCollectionView? How do I bind for example in a form to properties that are in the Person Class?

Like:

<TextBox Text="{Binding FirstName, ElementName=source2}"/>

Everything seems to come back as IEnumerable or as CollectionViews (like the DATA binding in the samples) which aren't useful for a single entity.

I want a single persons entry, why do I want a CollectionView in which I cannot access properties directly.

I have also use the:

 LoadOperation<Person> oLoadOperation = oDataContext.Load(oDataContext.GetSinglePersonQuery());

I am very close to giving up on this RIA idea and just going with a normal WCF service as it is more predictable and manageable at this stage.


ctxt.Load(ctxt.GetEmployeeByNumberQuery("ABC123")).Completed += new System.EventHandler(EmployeeLoad_Completed);


void EmployeeLoad_Completed(object sender, System.EventArgs e)
{
    Employee myEmployee = (sender as LoadOperation<Employee>).Entities.FirstOrDefault();
}


hey just found this check it out I think this is what you want to do

http://jeffhandley.com/archive/2009/11/10/domaindatasource-single-record.aspx


        HumanResourceContext context = new HumanResourceContext();

        var addressquery = context.GetAddressesQuery();
        addressquery = addressquery.Where(a => a.AddressId == 1);

        context.Load(addressquery, (op) =>
            {
                Address address = op.Entities.FirstOrDefault();

                MessageBox.Show(address.Street1);
            }, null);


I presume you have your class decorated with [EnableClientAccess] ?

try

<TextBlock Text="{Binding Path=Person.FirstName}"
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜