Entries:
Comments:
Posts:

Loading User Information from Channel 9

Something went wrong getting user information from Channel 9

Latest Achievement:

Loading User Information from MSDN

Something went wrong getting user information from MSDN

Visual Studio Achievements

Latest Achievement:

Loading Visual Studio Achievements

Something went wrong getting the Visual Studio Achievements

Silverlight TV 44: Top Four Questions from the WCF RIA Services Forum

Download

Right click “Save as…”

Today on Silverlight TV, Deepesh Mohnani answers four of the questions most frequently asked in the popular WCF RIA Services forums. This is a great episode to watch and the first in a periodic series from the RIA Services team in which we will address the top questions from developers.

In this episode, Deepesh addresses the following questions:

POCO model

  • How do I pull data from a non-ef data source?
  • How do I do CUD on that?

Client Side Computed Properties

  • How do I create a client side computed property like total amount?
  • How do I update a computed property when one of the dependency property changes?

Protect my service

  • How do I control access to methods?
  • How do I control access by Roles?

Windows Authentication

  • How do I enable Windows Authentication?
  • How do I integrate with Active Directory properties?

Relevant links:

Follow us on Twitter @SilverlightTV or on the web at http://silverlight.tv 


book 

Are you developing with Windows Phone 7? You can pre-order Learning Windows Phone Programming by Jaime Rodriguez, Yochay Kiriaty, and John Papa! Or check out the book's website.

Tags:

Follow the Discussion

  • John Papajopapa Evangelist on the Loose

    This is "test" show for us on answering questions from all of you. We'd love to hear your feedback on this format and if we should plan a few more like this.

  • With windows authentication, can you assign attributes to a method in your domain service like when using forms auth, such as [RequiredRoles("admin")] that then matches to a domain group? Or do you loose these attributes and have to implement your own code checking/exception handling? 

     

    Oh and i think the show was informative! But you did cover POCO classes a couple of shows ago which i felt could and i felt the time could of been utilised to cover more advanced areas in the topic. What i find alot of the time with these shows, are they are great at explaining the concepts in basic terms, but often real world scenarios arnt as straight forward so things like  highlighting windows auth is a good step forward but i think you need to relate the concepts back to the basic/featuresets and fully dislcose what you gain and what you loose from the framework. 

  • @dentedduck - There is no need to update the client, code gen will take care of it for you.

    @Weqster - You can assign attributes when using Windows Authentication, you will need to however hook up the roles provider.

  • John Papajopapa Evangelist on the Loose

    @Weqster - Yes, you can apply the attributes for roles to them when using the roles provider. It's often good to set it at a granular level.

  • Hi, This was great stuff.

     

    Deepesh could you post a app with the code examples.  I can't figure out how you did the data binding for the user object to the UI

     

     

  • I have not had a chance to blog about this but those interested in the source code and find the demo project here.

    http://cid-9d24497f7fef8f33.office.live.com/self.aspx/Demo/Episode2.zip

  • Great show John!  Great demo by Deepesh - well done.

  • How do you create a calculated field based on child objects?  For example, if you have an Order object that exposes a Total property based on a child Item.Price value, how can Item.Price notify Order to update its Total property (Order.Total) ?

     

    So you would have Order.Items[1].Price = 2.25;  Then Order.Total would be updated to reflect the change made to the Item.Price property.

     

    Thanks!

  • Thank you Deppesh and of course Thanks John Papa for this great tutorial video.

     

    I have the same question as Aaron on how to use to calculate vertical formulas based on the child values

     

     private void UpdateOrdersCount() { if (fOrdersCount == null) { fOrdersCount = Convert.ToInt32(this.Evaluate(CriteriaOperator.Parse("Orders.Count"))); } } private void UpdateOrdersTotal() { foreach (Order detail in Orders) { fOrdersTotal
     += detail.Total; } } 

    Also

    what about using Foreign values on formulas,

    on the invoice for example

    when a new invoice is created is necessary to add the Total Amount to the customer AmountDue

     

    Thanks Smiley

  • I also wanted to add the following scenario.  I have had no luck supporting this type of domain model pattern with WCF RIA, due to lack of supplied events.

     

    Debug.WriteLine(Order.Total); // outputs 0

    Item newItem = new Item() { Price = 30 };

    Order.Items.Add(newItem);

    Debug.WriteLine(Order.Total); // outputs 30

    Order.Items.Remove(newItem);

    Debug.WriteLine(Order.Total); // outputs 0

     

    Thanks again!

  • This scenario requires a little more work client-side, but you can capture the CollectionChanged event from your child collections to surface this kind of functionality.  Keep in mind that you should probably look at the WeakEventListener patterns out there to do this in a more 'appropriate' fashion.  This code is also thrown together 'off the cuff', so there may be syntactical errors as well.

     

    public partial class Order { 
      /// ... code 
      partial void OnCreated() { 
        LineItems.CollectionChanged += (s, e) => { RaisePropertyChanged("Total"); };
    
      } 
     
      public decimal Total { 
        get { 
          return (decimal)LineItems.Select(i => i.UnitPrice * i.Quantity).Sum(); 
        } 
      } 
    }
     

     

  • Thanks, that will address the second issue.  But what about when Item.Price changes?  How would I update Order.Total in that scenario? 

    If memory serves, the changed event of an Entity property only fires once, which doesn't really work how you would expect it.  So am I left to create my own event and handle this scenario manually?

     

    Thanks again!

  • John Papajopapa Evangelist on the Loose

    antwhite - I'm not sure I follow you correctly. If you have a calcualted column the purpose is generally for display purposes and not to update it directly. Generally you update the fields tha tgo into the calculation which then updates the calc'd column. So I am not sure why you would want the calc'd column ever be involved in a create or update.

     

    Help me understand

  • Again, this probably isn't the best solution, but really for derived properties like that, you'll need to notify upstream whenever you change.  One approach is to create a 'ExtendedPrice' type column on your LineItem entity which does the UnitPrice * Quantity calculation, then use the OnUnitPriceChanging/OnQuantityChanging methods to fire change notifications for your ExtendedPrice property.  Then you'd need to enhance the CollectionChanged handler to also attach handlers for the OnPropertyChanged events of the child objects and fire your Total changed event from there.

     

    HOWEVER, you may begin to wonder if this type of behavior is something you want built into your MODEL, or if you want to build it into your VIEWMODEL [assuming you're using MVVM].  If you want it built into your VIEWMODEL, then you can actually create a 'smart' observable collection that handles attaching to the contained items OnPropertyChanged events and do things that way, then have your smart collection be what is exposed in your VIEWMODEL and bound.

     

    Once you've done the above, then you could potentially extend that collection to give you your total price as an event on change, as an actual observable property of the smart collection, etc, you really open up the options.  RIA services, when using the model natively on the client, can really be a limitation for extension, and if you want rich UIs, you'll often find yourself binding NOT to the LineItems collection hanging off your Order object, but rather to a LineItems collection hanging off your OrderViewModel or some such that gives you more flexibility.

     

    A third option, which feels very 'smelly' would be to somehow invoke the Order object's PropertyChanged event FROM the LineItem class through the navigation property, so when unit price or quantity changes, the line item causes the Order's property change notification to fire explicitly if the associated Order navigation property is non-null...  Not necessarily good design, but certainly feasible.

     

  • larsmlarsm

    RIA Entity Set limitations.
    When working with RIA Services Entitiy Sets in my ViewModel, I find it very useful to wrap them into a PagedCollectionView before binding to the View. This gives the VM a lot a flexibility with regards to on-the-fly grouping, filtering and sorting.
    To my great surprise, I've discovered that the EntitySet is not inheriting IList, and some core features in the SDK and the Toolkit are based on this, the most important ones being DataForm Add/Remove button and DragDrop RemoveItem from Drag Source.
    So -  to my questions:
     - Why this limitation in the EntitySet?
     - What other controls may give me surprises because of this (that I haven't experienced yet)?
     - Is there any work in progress to add List/IList to the EnititySet in future releases of RIA Services?
    Thanks in advance
    LarsM

  • Kyle McClellanKyle McClellan

    @larsm
    In the next release, EntitySet will implement ICollectionViewFactory. It still won't be usable as a list, but it will be usable in collection view scenarios (binding to a DataGrid or DataForm). In the future we'll work on providing a collection view that works well in MVVM scenarios.

  • These answer sessions are actually very very helpful. This one, along with #41 have been crucial for understanding some of the lesser-demoed and sampled, yet common issues surrounding RIA Services.

    It seems that there is some need for the integration between the topics specific to RIA and topics specific to combining that with MVVM patterns, as opposed to the typical "in a real app you'd probably want to put this logic in your VM/IoC container/ using commands, etc..". 

    These have been very helpful in explaining a lot of the 'duh' techniques that clearly the frameworks are meant to address, but seem to be glossed over in lieu of more advanced topics.

    In short, DON'T STOP THESE! Big Smile

  • Hello everyone,

    I think it can be done doing this:

    For the group you must check for collectionchanged. Then you must create a method for update.

     public partial class GroupAction
        {
            protected override void OnLoaded(bool isInitialLoad)
            {
                base.OnLoaded(isInitialLoad);
                ((INotifyCollectionChanged)this.SingleActions).CollectionChanged += (s, e) =>
                    {
                        RaisePropertyChanged("TotalCost");
                    };
            }
    
    
            public void UpdateProperty(string name)
            {
                RaisePropertyChanged(name);
            }
    
            //[Bindable(true, BindingDirection.TwoWay)]
            [Editable(false)]
            public decimal TotalCost
            {
                get
                {
                    return this.SingleActions.Sum(sa => sa.Total);
                }
            }
    
    
        }

     

    then call the update method from the child:

      public partial class SingleAction
        {
              
            partial void OnPriceChanged()
            {
                RaisePropertyChanged("Total");
    
                if (GroupAction != null)
                    GroupAction.UpdateProperty("TotalCost");
            }
            partial void  OnQuantChanged()
            {
                RaisePropertyChanged("Total");
                if (GroupAction != null)
                    GroupAction.UpdateProperty("TotalCost");
            }
    
            //[Bindable(true, BindingDirection.TwoWay)]
            [Editable(false)]
            public decimal Total
            {
                get
                {
                    return this.Price * this.Quant;
                }
            }

     

    Cheers

  • Al AlbertoAl Alberto

    @jopapa:Most definitely yes!

  • PilotBobPilotBob

    Good video... is there a way to do (populate) a calculated column on the server side? The calculation we need to do depends on data from another entity. If we create the calculated column on our entity in a partial class, that works on the server of course, but the value is not martialed back to the client. 
    Also, can we do it in a way that we are returning a query rather than a list (which I think would work) so that it can be composed with a client side query for paging/sorting, etc?
    BOb
     
     
     

  • @PilotBob: Have you marked the member with the DataMember attribute?

  • PilotBobPilotBob

    @Despesh
    Won't that just cause the property to be code genned to the client side? It won't address the fact that their is code that can't run on the client? 
    Lot's of comment spam here. Would love to continue this via email if possible. My email is bob AT archer DOT net . Thanks for the help.
    BOb
     

  • RasikaRasika

    @jopapa: 
    It would be great if you could demo a scenario where you get a projection of several entities as a queryable  from domain service. but just few properties from those entities as a POCO class
    for: ex
    return
    from d in this.ObjectContext.Dept join e in this.ObjectContext.Emp on e.Dept equals d 
    // some where clause goes here to filter the departments
    select new DisplayData() { d.DepName, e.EmpName };
    In such situation how to do paging from client side and pass FilterDescriptors to the where clause as client side only see DepName and EmpName. 
    Could you cover such complex scenario if possible
     
     

  • heellaspireheellaspire


    .

    .

    .

  • heellaspireheellaspire


    .

    .

    .

  • emitoennyemitoenny


    .



    .

  • emitoennyemitoenny


    .



    .

  • snoliorissesnoliorisse

    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .

  • snoliorissesnoliorisse

    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .
    .

  • HAILLAWHOCAHAILLAWHOCA


    .



    .

  • sceriaweitasceriaweita

    ............
    ............

Remove this comment

Remove this thread

close

Comments Closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.