Silverlight TV 52: Entity Level Validation, Defining MetaData and Nested ComboBoxes with WCF RIA Services

Sign in to queue

Description

In this video, John sits down with Kyle McClellan of the WCF RIA Services team and responds to top questions from the RIA Services forums. Kyle runs through various scenarios and provides great guidance on how to identify and solve these issues. Here are some of the topics he covers:

  • How do I investigate exceptions thrown from my DomainContext?
  • How do I add a ComboBox to a DataGrid or DataForm?
  • How do I change the default metadata on an Entity when using the LinqToEntitiesDomainService?
  • How do I add cross-field validation to an Entity?

Relevant links:

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

Register now for the Silverlight Firestarter, Dec 2, 2010!

Firestarter

 

Embed

Download

Download this episode

The Discussion

  • User profile image
    jopapa
  • User profile image
    Atif Shahzad

    Hi good Video i have a question about DomainService i am working on a project using RIA and i have almost 150 entities i created a Domain Service for 95 entities now i want to pull rest of the entities from EF model but i did'nt find any method to update the Domain Service only one option is there to recreate the DomainService i had alot of server side code inside my DomainService so would you please tell me any solution to update DomainService.

  • User profile image
    Clinton Kimsing

    @Atif Shahzad: Try creating a completely new domain service, manually copy code from existing service into new service to consolidate the code. Unfortunately seems to be the only way at the moment

  • User profile image
    jopapa

    @Clinton Kimsing & @Atif Shahzad:

    Yes, currenty the way I do it is to create a new domain service with the new entities, then copy and paste the new code to the existing domain service. This is pain, but all in all only takes a little bit of time. I certainly hope this is a feature on the vNext list.

    Perhaps we'll add this to the next RIA Services "forums" episode of SL TV if there is enough interest.

  • User profile image
    Jason Porter

    Awesome video as usual John.  These vides are great way to chip away at the mysteries that are inherent in any new framework.  I have developed a full navigation based RIA service solution but I am still nervous whether I have implemented it the best way.  For instance in my application when I go from page to I instantiate the domain context and load my data to populate the UI.  Although the application works, I worry whether I am using the best practices.  It feels like I should use one domain context at application level which is shared between all the pages and that when I navigate to a page if the data is already loaded and not change that I would not load it again.  I would love to see a video that shows some best practices on sharing application wide data between pages, avoiding unnecessary sever loads and better explains things like ApplicationLifetimeObjects.  For instance, I don't know whether it is a good idea to add my domain context to the ApplicationLifetimeObjects the same way that the webcontext is added to it by default.
    Sincerely,
    Jason

  • User profile image
    Jim Stott

    One item comes to mind when you talk about forgetting to set/rest customErrors mode=On/Off is using Web.Release.Config to replace the element for the target "Release" when building for production.  

  • User profile image
    dotnetscott

    another great vid guys ty!

    As a suggestion in regards to more metadata validation would be:

    1) How to use Resource files to hold the validation strings.

    2) How to make the code generation actually work across multiple projects in the same solution when using those Resource Files.

    Thanks!

  • User profile image
    Hector Hernandez

    Thanks for the video John ... I implemented what I saw here but I've got a problem! ...
    Description:
    I have a button to save the changes of the context. .. Context.SaveChanges()but anytime I press it I have an error because the entity is still in Edit Mode ... there are some samples on the net where you can close the Edit Mode of entities like this

    Modules.ToList().ForEach(uur => (uur as IEditableObject).EndEdit());

    But then I SaveChanges and get back an Exception that explains that validation failed at the server ... so validation is making its work in the client and server HOWEVER!!!
    I am trying also this before the call to Context.SaveChanges()

    if
    (Modules.Where((pcm) => pcm.HasValidationErrors == true).Count() > 0) { return; }
    This is for checking if there is any Entity with an error... the thing here is THAT NONE ENTITY returns from this linq ... WHAT IS WORSE ... I know exactly the number of Entity with the error into my Modules list ... I call directly Modules[6].HasValidationErrors and the result is alwas FALSE ... EVEN WORSE ... Calling Modules[6].MyField shows me that the value inserted into MyField for the given Module is NOT THE CORRECT ONE but the Entity is telling me that it has no Validation Errors...
    Is there a way of checking for ValidationErrors in my ViewModel before calling Context.SaveChanges? ...
    THANKS!

  • User profile image
    Kyle McClellan

    I've found edit sessions are typically only left open by the DataForm. In this post (https://blogs.msdn.com/b/kylemc/archive/2010/10/28/improved-binding-support-in-entityset-and-entitycollection.aspx) I show how to track the DataForm state and close the session correctly. Additionally, if you close using CommitEdit, it will do a validation pass and you will be able to correctly detect errors before submitting.

  • User profile image
    Atif Shahzad

    @jopapa:Thankx Kyle McClellan for replay and hopefully we shall have this feature in vnext, but for now iam doing this manually.

  • User profile image
    Hector Hernandez

    @Kyle McClellan:
    Thank you very much ... ~!!!

  • User profile image
    Leo

    I do not know what to do anymore, this is getting me crazy... all i get when an error like he cause on 03:36 happens, its a blank screen, my SL app dissapear. I can get the error on fiddler, but it would be better to see on screen. I have used the business template and my RIA services are on a separated project... all works fine, but this problem is getting me crazy. If I use IE9, I get a windows popup asking me if i want to debug the error on a new instace of vs2010!... RIA Services is amazing, but problems like this are very frustrating :/ (and sorry for my bad english)

  • User profile image
    racicjovan

    Do you know what could be reason for problem to watch or downloaf this video. I have to wait every few seconds for buffeing (I think). It is very frustrating and I am interested if there is any problem with some WMP or like this options.(I am able to watch other videos - on Facebook or any other source smoothly)

  • User profile image
    shadowdog

    Hi John,
    Can you cover how Entity level validation is acheived in server side code. I am inserting object as new entities into the db but would like to validate each field prior to insertion on the server (object sent via WCF so no client side validation is done prior).

  • User profile image
    pavle

    @Atif Shahzad:Make Partial Class-es for both Metadata and Code, and After that before making changes Exlude those partial class-es from project, add more entity, rebuild, generate domain service, include your partial class-es, and that's it, After that what ever you change put in your partial class-es, and you are not going to lose any of your code, just repet all of these when you had to add more entity!!! Hope this helps!!!

Add Your 2 Cents