views:

856

answers:

6

Hi there,

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:

<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.

A: 

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

try

<TextBlock Text="{Binding Path=Person.FirstName}"
ozdeveloper
+1  A: 

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

ozdeveloper
Hopefully my blog post that ozdeveloper pointed you to was able to answer your question. If not, let me know.
Jeff Handley
A: 

Anyone else noticed how much slower the DomainDataSource is compared to Loading the data in the Load<> method?

Oliver
Oliver... I'd love to hear more about this. DomainDataSource should not have much overhead over the Load<> method. Feel free to contact me on my blog to discuss. http://jeffhandley.com (DomainDataSource developer)
Jeff Handley
A: 

I think it is ridiculous that RIA does not let you deal with a single entity retrieval in a more graceful way. If I write a "GetCustomerById" method on my DomainService, I would expect to be able to easily call this from the web application in a first-class "single-entity" kind of way. However, it seems the code-generation part of RIA was designed to just deal with multiple records, which seems crazy as there are all kinds of use cases where only a single entity is desired.

Mike Gates
A: 
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();
}
Coolwayfarer
A: 

I have a desperate, real life question/situation .. I created a Silverlight Business Application .. and have added 4 pages in addition to the main, home, and about pages. 1.Each page is one of your completed chap 09 solutions .. 2.On each “page” I go to my database for the Products download. 3.Example: Page 1. I go to the SQL data and create my product context. Everything is cool. When I go to Page 2, why do I have to go back to the SQL database and re download the data. I think I already have it in my DomainContext.Entities. I am assuming that the data is in the domain universe, somewhere .. can I access it without having to return to the SQL database when I go to a new page? Thanks

Frank