Join two table

Posts   
 
    
Posts: 24
Joined: 01-Dec-2006
# Posted on: 19-Mar-2007 14:39:06   

I want to define a typedlist using in the code. There are 2 tables. One is Bolum the other is KkBolum. BolumKodu and OrgFirmaKodu fields are primary keys in the "Bolum" table and foreign keys in the "KkBolum" table.

Here is example.

           DataTable results = new DataTable();
           ResultsetFields fields = new ResultsetFields(5);

            fields.DefineField(BolumFields.OrgFirmaKodu, 0);
            fields.DefineField(BolumFields.BolumKodu, 1);
            fields.DefineField(BolumFields.BolumAdi, 2);
            fields.DefineField(KkBolumFields.OrgFirmaKodu, 3);
            fields.DefineField(KkBolumFields.BolumKodu, 4);

            IRelationPredicateBucket bucket = new RelationPredicateBucket();
            bucket.Relations.Add(BolumEntity.Relations.KkBolumEntityUsingOrgFirmaKoduBolumKodu, "KkBolum", "Bolum", JoinHint.None);

            _adapter.FetchTypedList(fields, results, bucket, 0, null, true, null);

but there is an error : "An item with the same key has already been added"

JimHugh
User
Posts: 191
Joined: 16-Nov-2005
# Posted on: 19-Mar-2007 14:55:26   

The two lines below use the same field name, I think you need to add an alias for the second duplicate field name.


fields.DefineField(BolumFields.BolumKodu, 1);
fields.DefineField(KkBolumFields.BolumKodu, 4);

//try this instead
fields.DefineField(KkBolumFields.BolumKodu, 4, "BolumKodu2");

Posts: 24
Joined: 01-Dec-2006
# Posted on: 19-Mar-2007 16:31:00   

I have tried it but then it gives other error. It can't find any field name with that allias.

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 20-Mar-2007 01:41:32   

How about something like this. The fields need to have the alias defined with them, or don't reference the second set of columns.


            DataTable results = new DataTable();
            ResultsetFields fields = new ResultsetFields(5);

            fields.DefineField(BolumFields.OrgFirmaKodu, 0, "Bolum");
            fields.DefineField(BolumFields.BolumKodu, 1, "Bolum");
            fields.DefineField(BolumFields.BolumAdi, 2, "Bolum");
            fields.DefineField(KkBolumFields.OrgFirmaKodu, 3, "KkBolum");
            fields.DefineField(KkBolumFields.BolumKodu, 4, "KkBolum");

            IRelationPredicateBucket bucket = new RelationPredicateBucket();
            bucket.Relations.Add(BolumEntity.Relations.KkBolumEntityUsingOrgFirmaKoduBolumKodu, "KkBolum", "Bolum", JoinHint.None);

            _adapter.FetchTypedList(fields, results, bucket, 0, null, true, null);