none
WCF RIA zero-one to many ultimate treeview RRS feed

  • Question

  • Hi,

    I am using ultimate treeview extension (http://visualstudiogallery.msdn.microsoft.com/ca292c74-661c-48ba-8262-d79a2671c33f)

    This requires a zero-one to many table. I have this working with a table.

    However I need to connect to a WCF RIA service from the control. Currently using 

     public class WorksOrderTree

        {
            [Key()]
            public int id { get; set; }
           
            [Association("ProductPart", "id", "ParentID")]
            public IEnumerable<WorksOrderTree> Children { get; set; }
            [Association("ProductPart", "ParentID", "id", IsForeignKey = true)]
            public WorksOrderTree Parent { get; set; }
            public int ParentID { get; set; }

    }

    This gives the following error

    Error 1 f0rmoum1..csdl(26,6) : error 0113: Multiplicity is not valid in Role 'WorksOrderTree' in relationship 'ProductPart'. Because all the properties in the Dependent Role are nullable, multiplicity of the Principal Role must be '0..1'.

    Any idea to to how create zero-one to many in the ria service.

    Thanks

    Steve

    Tuesday, September 18, 2012 10:06 PM

All replies

  • Same problem here, any update to this thread ?

    AAK

    Friday, July 19, 2013 9:12 AM
  • Just a hunch, but the ParentID property above should be nullable....?

    Regards, Xander

    Friday, July 19, 2013 11:54 AM
  • I'm doing it as follows:

     public class DepartmentDTO
        {
            [Key]
            public int ID { get; set; }
            public string DepartmentName { get; set; }
             public int? ParentID { get; set; }
            [Association("MyRef", "ParentID", "ID", IsForeignKey = true)]
            public DepartmentDTO ParentDepartment { get; set; }
            [Association("MyRef", "ID", "ParentID", IsForeignKey = false)]
            public IQueryable<DepartmentDTO> ChildDepartments { get; set; }
            
        }
    So, not only a nullable reference to the parent, but also an IQueryable for the child collection.


    paul van bladel

    Friday, July 19, 2013 12:55 PM
  • Wow !!! you make my day !

    Do you know that this question does not have any answer yet ! I have goggled it for a week with no luck !

    Thanks a lot....


    AAK

    Friday, July 19, 2013 6:07 PM
  • Ok now I have another Question: It seem that LightSwitch does not load the "Parent" when calling this Ria Service, any idea to enfore it to include the parent in the call ?

    AAK

    Friday, July 19, 2013 8:07 PM
  • It's good that the parent is not loaded eagerly. If the parent was loaded, than the parent of the parent, etc. ... would be loaded as well (until the root). This would have a performance impact on your tree.

    If you simply want some data from the parent, why not simply extend the structure of your RIA data transfer object with the parent related fields you need:  E.g.  ParentDepartmentName, ParentDepartmentLocation.

    You can find on my blog some examples of using the Telerik treeview control, which supports load on demand out of the box (blog.pragmaswitch.com). Obviously, the load on demand is about loading child entities on demand, not the parent.


    paul van bladel

    Saturday, July 20, 2013 9:22 AM
  • Thanks for your reply Paul.

    Yes I read your blog about the Telerik treeview and it was very helpful. the problem is that I want to use the Telerik RadTreeListView control instead, and It seem that it cannot be used with LightSwitch (for threading problems...)

    So I am obliged to create a RIAService ( that I hope) it can return a hierarchical structure without any lazy loading, so the RadTreeListView can work....

    but It seem that RIAService (Or LightSwitch) Insists on lazy load, and I don't know how to avoid it...

    I know that I can create a service in my UserControl project as you say in your blog but I am trying to create a LightSwitch extention ....


    AAK

    Monday, July 22, 2013 8:38 AM
  • I think that lazy loading is only one possibility in custom RIA service with Lightswith (v1). Eager loading is not working for me.
    Monday, August 5, 2013 8:42 AM
  • Lazy/eager loading has not directly something to do with a RIA service.

    When you work with a custom control, it's also possible to NOT use the LightSwitch viewmodel and connect directly over the odata service. That way of working allows to eager load data.

    That's described here: EAGER LOADING RELATED ENTITIES IN LIGHTSWITCH 2012 IN A CUSTOM CONTROL

    Note that eager loading can be beneficial in some scenario's but not definitely not in the majority of cases.


    paul van bladel

    • Proposed as answer by robertofillho Wednesday, February 18, 2015 8:17 PM
    Wednesday, August 7, 2013 6:45 AM
  • Please Try it:

       public class SkyCondition
        {
            [Key]
            public int Id { get; set; }
            [Include]
            [Association("MetarSkyCondition", "IdMetar", "Id", IsForeignKey = true)]
            public Metar Metar { get; set; }
        }

        public class Metar
        {
            [Key]       
            public int Id { get; set; }
            [Association("MetarSkyCondition", "Id", "IdMetar")]
            public ICollection<SkyCondition> SkyConditions { get; set; }
        }

    Wednesday, February 18, 2015 8:17 PM