Reverse Mapping - Map Mapping Help

3 posts, 0 answers
  1. Axe
    Axe avatar
    88 posts
    Member since:
    Feb 2007

    Posted 02 Sep 2009 Link to this post

    I'm learning OpenAccess and using an existing database so I'm reverse mapping.
    I have a mapping/joining table that has 3 Primary keys that have relationships to 3 tables.

    Owner Class - Track
    Key Type - Industry
    Value Type - IndustryType

    The skeleton classes:
    public partial class Track  
    {  
        //The 'no-args' constructor required by OpenAccess.   
        public Track()  
        {  
        }  
     
        [Telerik.OpenAccess.FieldAlias("trackID")]  
        public int TrackID  
        {  
            get { return trackID; }  
            set { this.trackID = value; }  
        }  
     
        [Telerik.OpenAccess.FieldAlias("trackIndustries")]  
        public IDictionary<Industry, IndustryType> TrackIndustries  
        {  
            get { return trackIndustries; }  
        }  
    }  
     
     
     
    public partial class Industry  
    {  
        //The 'no-args' constructor required by OpenAccess.   
        public Industry()  
        {  
        }  
     
        [Telerik.OpenAccess.FieldAlias("industryID")]  
        public int IndustryID  
        {  
            get { return industryID; }  
            set { this.industryID = value; }  
        }  
    }  
     
     
    public partial class IndustryType  
    {  
        //The 'no-args' constructor required by OpenAccess.   
        public IndustryType()  
        {  
        }  
     
        [Telerik.OpenAccess.FieldAlias("industryTypeID")]  
        public int IndustryTypeID  
        {  
            get { return industryTypeID; }  
            set { this.industryTypeID = value; }  
        }  
    }  
     

    The "TrackIndustries" table has data like:
    TrackID    IndustryID    IndustryTypeID
    1              44                12
    1              44                15
    1              44                17
    1              44                15

    If I make a query such as:
    var items = scope.Extent<Track>().Where(t => t.TrackID == 1).SingleOrDefault().TrackIndustries; 
    I only get back 1 result instead of 4

    Should I not use a "Map" Mapping here?
    I also need to query this from the Industry class as well to say give me the Tracks where Industry == ?

    I can do all this with sql easily but not sure how to do it here.

    Any ideas?

    If you need more info let me know.

    Thanks
  2. Axe
    Axe avatar
    88 posts
    Member since:
    Feb 2007

    Posted 05 Sep 2009 Link to this post

    I just realized I can't use an IDictionary for this purpose because of duplicate keys.
    So I guess I will have to implement this like your example Handling Many-To-Many (M:N) relation with additional link information

    I will give it a go and see how it goes.
  3. DevCraft banner
  4. PetarP
    Admin
    PetarP avatar
    754 posts

    Posted 09 Sep 2009 Link to this post

    Hello Axe,

    Yes you correct. Using duplicated keys in your dictionary will cause problems. Try to implement the approach provided in our Knowledge base and please, do not hesitate to contact us if you face any difficulties.

    All the best,
    Petar
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top