This is a migrated thread and some comments may be shown as answers.

Reverse Mapping - Map Mapping Help

2 Answers 69 Views
Development (API, general questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Axe
Top achievements
Rank 1
Axe asked on 02 Sep 2009, 01:51 PM
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 Answers, 1 is accepted

Sort by
0
Axe
Top achievements
Rank 1
answered on 05 Sep 2009, 10:41 AM
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.
0
PetarP
Telerik team
answered on 09 Sep 2009, 06:20 AM
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.
Tags
Development (API, general questions)
Asked by
Axe
Top achievements
Rank 1
Answers by
Axe
Top achievements
Rank 1
PetarP
Telerik team
Share this question
or