1-888-365-2779
+1-888-365-2779
Try Now
More in this section

ORM question

3 posts, 0 answered
  1. leroy
    leroy avatar
    5 posts
    Registered:
    06 Feb 2008
    11 Feb 2008
    Link to this post
    Hi All,

    I am very new to ORM. I have played around with it a little in LINQ, but I need a little guidance.

    I have a Artist table, Address table and Images table and I want to retrieve fields from all these separate tables using a List<Artist>.

    In a non-ORM world I would usually retrieve these using a specialised stored procedure and then looped through and populate a class list.

    Using Subsonic or Nolics how would I do this.

    I should probably posting this question somewhere else..

    Thanks in advance..

  2. bnye
    bnye avatar
    332 posts
    Registered:
    22 Sep 2005
    12 Feb 2008
    Link to this post
    leroy -

    Here is what I would do.

    Fist I would create a class project call something like youcompany.portfolio.data. Make sure you reference all of the necessary classes to make nolics work.

    Then I would add the following Nolics .dbclass files to that project.

    Artist.dbclass

    dbclass Artist[TableName="commerce_artist",WebBinder=true]      
    {     
      primary key guid ID[AutoGenGUID=True];  
      string FirstName;  
      string LastName;   
      relation ArtistImage [] ArtistImageArray;  
      relation ArtistAddress [] ArtistAddressArray;  
      version long Version;       
      created date CreatedDate;     
      modified date ModifiedDate;       
    }     
        
    namespace queries;     
        
    query GetArtitst for Artist[ProcedureName="commerce_getartist",OrderBy="CreatedDate DESC",WebBinder=true]     
    {     
        guid ID ?= ID;     
    }    
     

    ArtistAddress.dbclass

    dbclass ArtistAddress[TableName="commerce_artistaddress",WebBinder=true]      
    {     
      primary key guid ID[AutoGenGUID=True];  
      string Address1;  
      string Address2;  
      string City;  
      string StateOrRegion;  
      string Zip;  
      string Country;  
      link Artist Artist_lnk: guid ArtistID;  
      version long Version;       
      created date CreatedDate;     
      modified date ModifiedDate;       
    }     
        
    namespace queries;     
        
    query GetArtitstAddress for ArtistAddress[ProcedureName="commerce_getartistaddress",OrderBy="CreatedDate DESC",WebBinder=true]     
    {     
        guid ID ?= ID;    
        guid ArtistID ?= ArtistID;   
    }   

    ArtistImage.dbclass

    dbclass ArtistImage[TableName="commerce_artistimage",WebBinder=true]      
    {     
      primary key guid ID[AutoGenGUID=True];  
      string Name;  
      string UniqueName;  
      string Description;  
      string ImageOriginal;  
      string ImageThumb;  
      string ImagePoster;  
      string ImageFull;  
      long Order;  
      link Artist Artist_lnk: guid ArtistID;  
      version long Version;       
      created date CreatedDate;     
      modified date ModifiedDate;       
    }     
        
    namespace queries;     
        
    query GetArtitstImage for ArtistImage[ProcedureName="commerce_getartistimage",OrderBy="CreatedDate DESC",WebBinder=true]     
    {     
        guid ID ?= ID;    
        guid ArtistID ?= ArtistID;   
    }   

    Then I would add this project to my website solution.

    Now you can referece your strongly typed classes in the website by adding the imports (vb.net) yourcompany.portfolio.data.

    Now you load your initial list of artists

    dim query as new queries.GetArtists  
    query.loadall  
     
    for each artist as Artist in query  
         for each image as ArtistImage in artist.ArtistImageArray  
                 'do something  
         next  
         for each address as ArtistAddress in artist.ArtistAddressArray  
                'do something  
         next  
    next  
     


    That's it. You have already loaded your class with information from all three tables. For exampe if I want to display a thumbnail image for every image and show who it was by.

    dim query as queries.GetArtistImage  
    query.LoadAll  
     
    for each image as ArtistImage in Query  
        'imageurl = image.ImageThumb  
        'Artist = image.Artist_Lnk.FirstName  
    next 

    I hope that starts you on the right track to finding your answer. If not let me know and I can try again.

    Sincerely,

    Ben
  3. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    14 Feb 2008
    Link to this post
    Hello bnye,

    Thank you for providing a solution. Your Telerik points have been updated.


    Greetings,
    Georgi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Register for webinar
3 posts, 0 answered