CodeSmith Community
Your Code. Your Way. Faster!

Binding DeepLoad methods programmatically

Latest post 06-30-2008 4:48 AM by JoyalJJ. 1 replies.
  • 10-28-2006 10:45 AM

    • Axe
    • Top 500 Contributor
    • Joined on 10-17-2006
    • Sydney, AU
    • Posts 14
    • Points 460

    Binding DeepLoad methods programmatically

    Hi everyone,

     I've only just started looking into .netTiers (last 5 days) and have been reading all the documentation and playing with the code. Some parts seem easy to use and others a bit harder to work out. As great as the datasource controls are I really would like to work with the code. I'm currently working on a portion of a project which has alot of Many-To-Many relationships which I normally hand code all the methods. Came across these templates and thought it might save me some time.

    Where I'm stumbling is getting stuff to bind to controls.
    I can use a simple Service Layer method directly on say a GridView:
    eg.

       11     private IndustryService industryService;

       12     protected IndustryService iService

       13         {

       14             get

       15             {

       16                 if (industryService == null)

       17                     industryService = new IndustryService();

       18 

       19                 return industryService;

       20             }

       21         }

       22     protected void Page_Load(object sender, EventArgs e)

       23     {

       24         int addressID = 1;

       25         gvTest.DataSource = iService.GetAll();

       26         gvTest.DataBind();

       27 

       28         //And even can get to something like this no problem

       29         gvTest2.DataSource = iService.GetByAddressIDFromIndustryAddress(addressID);

       30         gvTest2.DataBind();

       31     }

     

    What I'm not getting is DeepLoad. I went to the samples page (http://nettiers.com/Samples.aspx) which has at the bottom of page: Working with the Code

     

    string custId = "TRAIH";
    
    //I get a single instance of the customer I want.
    Customers customer = DataRepository.CustomersProvider.GetByCustomerID(custId);
    
    Type [] typesToDeepLoad = new Type[] { typeof(TList<Orders>), typeof(TList<Products>) };
    
    //go further than one level down object graph
    bool goMoreThanOneLevelDeep = true;
    
    // I'm going to deep load this customer, but I only want 
    // to see his orders and the products that he's made, 
    // I really don't care about the line items
    // But the neat thing is that the relationship to products is through // line items.
    /// the object graph looks somethign like this
    /// - Customer
    /// --Order
    /// ---OrderDetails
    /// ---ProductCollection
    /// --CustomerDemographics
    /// --CustomerDemographicsCollection_From_CustomerCustomerDemo 
    ///   (a strangely named northwind thing, but shows how many to many relationships work.)
    
    DataRepository.CustomersProvider.DeepLoad(
    customer, // my customer
    goMoreThanOneLevelDeep, //go further than one level down object graph
    DeepLoadType.IncludeChildren, //be Inclusive, instead of exclusive
        typesToDeepLoad );
    
    

     

    I tried my own example which is good but I don't know what to do with it to get it bindable to a control. Don't know if it needs to be cast to something or if I'm totally off track.

     

       22     protected void Page_Load(object sender, EventArgs e)

       23     {

       24         TheLocalScene.Entities.Industry industry = DataRepository.IndustryProvider.GetByIndustryID(idIndustry);

       25         Type[] deepLoadTypes = new Type[]

       26         {

       27             typeof (TList<Engineer>)

       28         };

       29 

       30         DataRepository.IndustryProvider.DeepLoad(industry,

       31         true, DeepLoadType.IncludeChildren, deepLoadTypes);

       32 

       33         int idIndustry = 1;

       34         gvTest.DataSource = ???

       35         gvTest.DataBind();

       36     }

     

    I got heaps more questions going through my head but this is a good start.

    I just had a quick look again before posting and tried using the Service Layer DeepLoad methods such as:

    GridView1.DataSource = iService.DeepLoadByIndustryID(1, true, DeepLoadType.IncludeChildren, deepLoadTypes);

    but get error saying Data source is an invalid type.  It must be either an IListSource, IEnumerable, or IDataSource. And this is where I get a bit confused. What make deepload so different.

     

    I'm going to put a sample database together based on what I'm trying to do so I can upload here and maybe someone can take a quick look.

     

    Appreciate your work :)

    Thanks

     

    btw. found a cool tool for visual studio to copy code as html: http://scottonwriting.net/sowblog/posts/9268.aspx

     

    When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth. - Sherlock Holmes, as recorded by Sir A. C. Doyle in "The Blanched Soldier"
    • Post Points: 35
  • 06-30-2008 4:48 AM In reply to

    • JoyalJJ
    • Not Ranked
    • Joined on 06-30-2008
    • Posts 3
    • Points 15

    Re: Binding DeepLoad methods programmatically

    Hi,

    It might be possible that you found alternate solution for your above question.

    But i would like to know you as well as other people who are having the same problem.

    For the above problem, you should replace your following line.

    GridView1.DataSource = iService.DeepLoadByIndustryID(1, true, DeepLoadType.IncludeChildren, deepLoadTypes);

    with,

    Industry=iService.DeepLoadByIndustryID(1, true, DeepLoadType.IncludeChildren, deepLoadTypes);

    TList<Industry> t= new TList<Industry>();

    t.Add(Industry);

    GridView1.DataSource = t;

    GridView1.DataBind();

    • Post Points: 5
Page 1 of 1 (2 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems