Hypercell ein ] Hypercell aus ] Zeige Navigation ] Verstecke Navigation ]
c++.de  
   
Forentreff 2012     
Bücher-Shop mit Amazon (Buchkategorien)C++ : Referenzen zu C++ : C++ Builder : Visual C++ : C# : Java : Spieleprogrammierung : Systemprogrammierung Linux : Software-Entwicklung : .NET : Compilertechnik : Algorithmen & Datenstrukturen : Objektorientierung : Entwurfsmuster : UML : eXtreme Programming : Scrum : Projektmanagement : Software-Testing : Datenbanken : Tom DeMarco : Dilbert : User Friendly
C/C++ Forum :: C# und .NET ::  DataGrid als Row für DataGrid     Zeige alle Beiträge auf einer Seite Auf Beitrag antworten
Autor Nachricht
FrEEzE2046
Mitglied

Benutzerprofil
Anmeldungsdatum: 03.12.2008
Beiträge: 786
Beitrag FrEEzE2046 Mitglied 13:09:22 30.08.2010   Titel:   DataGrid als Row für DataGrid            Zitieren

Hallo,

ich habe zwei Tabellen, die eine n:m Beziehung zueinander haben, welche über eine Hilfstabelle realisiert ist.

Ich benutze unter Silverlight 4 das Entity Framework. Dort sind diese Assoziationen als Navigation Property geführt.

Ich hätte nun gerne, dass mur zu jedem Datensatz von Tabelle A alle zugehörigen Datensätze von Tabelle B in einem extra Grid (da ja auch andere Spaltennamen) angezeigt werden.

Ich stelle mir das so vor, dass ich jeden Eintrag Gruppieren kann (ungefähr wie beim PagedCollectionView).

Mir fehlt jedoch absolut der Ansatz dafür. Kann mir jemand weiterhelfen?
Firefighter
Mitglied

Benutzerprofil
Anmeldungsdatum: 27.03.2007
Beiträge: 2818
Beitrag Firefighter Mitglied 13:32:46 30.08.2010   Titel:              Zitieren

Ja klar, da gibts im Xaml eine Attached Property die heißt RowDetails und dort kannst du ein DataTemplate festlegen.

_________________
Mein Blog
Clean-Code-Developer
Wie man richtig Fragen stellt
FrEEzE2046
Mitglied

Benutzerprofil
Anmeldungsdatum: 03.12.2008
Beiträge: 786
Beitrag FrEEzE2046 Mitglied 14:35:56 30.08.2010   Titel:              Zitieren

Firefighter schrieb:
Ja klar, da gibts im Xaml eine Attached Property die heißt RowDetails und dort kannst du ein DataTemplate festlegen.


Vielen Dank für deine Antwort. Das scheint auch zu funktionieren.
Ich habe TabelleA und TabelleB als Entitäten importiert. Die Assoziationen kann ich über NavigationPropertys erreichen.
Den Inhalt meines "Haupt-"DataGrids hole ich mir über IQueryable<TableA>. Auf was muss ich das Binding nun im Unter-DataGrid setzen?
witte
Mitglied

Benutzerprofil
Anmeldungsdatum: 08.01.2008
Beiträge: 1295
Beitrag witte Mitglied 15:56:14 30.08.2010   Titel:              Zitieren

TableA sollte dann doch ein Navigation Property zu TableB haben. Diese Collection kannst du doch dann verwenden, sowas wie TableA.TableBList.
FrEEzE2046
Mitglied

Benutzerprofil
Anmeldungsdatum: 03.12.2008
Beiträge: 786
Beitrag FrEEzE2046 Mitglied 16:24:42 30.08.2010   Titel:              Zitieren

witte schrieb:
TableA sollte dann doch ein Navigation Property zu TableB haben. Diese Collection kannst du doch dann verwenden, sowas wie TableA.TableBList.


Die Get-Query liefert mir aber ein EntitySet bzw. IQueryable<TableA> zurück. Diese enthält folglich alle Sätze.
Was ich bräuchte wäre aber immer alle TableB-Datensätze bezogen auf 1nen TableA-Datensatz.

Code:
1
2
3
4
5
6
7
8
9
10
11
1
2
3
4
5
6
7
8
9
10
11
TableA:
- Properties
// [...}
- Navigation Properties
  TableBs

TableB:
- Properties
// [...}
- Navigation Properties
  TableAs
Code:
1
2
3
4
5
6
7
8
9
10
11
TableA:
- Properties
// [...}
- Navigation Properties
TableBs

TableB:
- Properties
// [...}
- Navigation Properties
TableAs
Code:
1
2
3
4
5
6
7
8
9
10
11
TableA:
- Properties
// [...}
- Navigation Properties
  TableBs

TableB:
- Properties
// [...}
- Navigation Properties
  TableAs


Assoziation ist * zu *
witte
Mitglied

Benutzerprofil
Anmeldungsdatum: 08.01.2008
Beiträge: 1295
Beitrag witte Mitglied 16:59:50 30.08.2010   Titel:              Zitieren

Ein ORM stellt keine Tabellen sondern Objektgraphen dar. Wenn du beispielsweise sowas wie
C# Code:
var qry = ctx.TableASet.Include("TableBSet");
C# Code:
var qry = ctx.TableASet.Include("TableBSet");
C# Code:
var qry = ctx.TableASet.Include("TableBSet");

machst, solltest eine Aufzählung von A's haben an denen über das Navigationsproperty für jedes A die entsprechenden B's dranhängen. Also A.BList oder wie immer das NavProperty heisst sollte dir die B's geben die mit diesem konkreten A verknüpft sind. Der Binding-path der ItemsSource könnte dann "A.BList" heißen.

Wenn die verknüpfende DB-Tabelle zwischen A und B noch weitere Attribute als die Fremdschlüssel besitzt dann mußt du diese miteinbeziehen
C# Code:
var qry = ctx.TableASet.Include("TableABMapper.TableBSet");
C# Code:
var qry = ctx.TableASet.Include("TableABMapper.TableBSet");
C# Code:
var qry = ctx.TableASet.Include("TableABMapper.TableBSet");

und dann entsprechend "A.ABMapper" als Path.

Sonst müßtest du mal konkret zeigen was du da machst.
FrEEzE2046
Mitglied

Benutzerprofil
Anmeldungsdatum: 03.12.2008
Beiträge: 786
Beitrag FrEEzE2046 Mitglied 17:18:12 30.08.2010   Titel:              Zitieren

Ich versuch es mal mit anderen Worten auszudrücken.

Ich habe folgende SQL-Tabellen:
TableA:
Code:
1
2
3
4
5
6
7
8
1
2
3
4
5
6
7
8
CREATE TABLE [dbo].[TableA](
    [aID] [int] IDENTITY(1,1) NOT NULL,
    [aName] [varchar](32) NOT NULL,
 CONSTRAINT [PK_aID] PRIMARY KEY CLUSTERED
(
    [aID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
Code:
1
2
3
4
5
6
7
8
CREATE TABLE [dbo].[TableA](
[aID] [int] IDENTITY(1,1) NOT NULL,
[aName] [varchar](32) NOT NULL,
CONSTRAINT [PK_aID] PRIMARY KEY CLUSTERED
(
[aID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
Code:
1
2
3
4
5
6
7
8
CREATE TABLE [dbo].[TableA](
    [aID] [int] IDENTITY(1,1) NOT NULL,
    [aName] [varchar](32) NOT NULL,
 CONSTRAINT [PK_aID] PRIMARY KEY CLUSTERED
(
    [aID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]


TableB:
Code:
1
2
3
4
5
6
7
8
1
2
3
4
5
6
7
8
CREATE TABLE [dbo].[TableB](
    [bID] [int] IDENTITY(1,1) NOT NULL,
    [bName] [varchar](32) NOT NULL,
 CONSTRAINT [PK_bID] PRIMARY KEY CLUSTERED
(
    [bID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
Code:
1
2
3
4
5
6
7
8
CREATE TABLE [dbo].[TableB](
[bID] [int] IDENTITY(1,1) NOT NULL,
[bName] [varchar](32) NOT NULL,
CONSTRAINT [PK_bID] PRIMARY KEY CLUSTERED
(
[bID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
Code:
1
2
3
4
5
6
7
8
CREATE TABLE [dbo].[TableB](
    [bID] [int] IDENTITY(1,1) NOT NULL,
    [bName] [varchar](32) NOT NULL,
 CONSTRAINT [PK_bID] PRIMARY KEY CLUSTERED
(
    [bID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

TableA_B:
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
CREATE TABLE [dbo].[TableA_TableB](
    [aID] [int] NOT NULL,
    [bID] [int] NOT NULL,
 CONSTRAINT [PK_Group_Module] PRIMARY KEY CLUSTERED
(
    [aID]] ASC,
    [bID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

ALTER TABLE [dbo].[TableA_TableB]  WITH CHECK ADD  CONSTRAINT [FK_TableA_TableB_TableA] FOREIGN KEY([aID])])
REFERENCES [dbo].[Group] ([aID])

ALTER TABLE [dbo].[TableA_TableB]  WITH CHECK ADD  CONSTRAINT [FK_TableA_TableB_TableB] FOREIGN KEY([bID])
REFERENCES [dbo].[Module] ([bID])
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
CREATE TABLE [dbo].[TableA_TableB](
[aID] [int] NOT NULL,
[bID] [int] NOT NULL,
CONSTRAINT [PK_Group_Module] PRIMARY KEY CLUSTERED
(
[aID]] ASC,
[bID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

ALTER TABLE [dbo].[TableA_TableB] WITH CHECK ADD CONSTRAINT [FK_TableA_TableB_TableA] FOREIGN KEY([aID])])
REFERENCES [dbo].[Group] ([aID])

ALTER TABLE [dbo].[TableA_TableB] WITH CHECK ADD CONSTRAINT [FK_TableA_TableB_TableB] FOREIGN KEY([bID])
REFERENCES [dbo].[Module] ([bID])
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
CREATE TABLE [dbo].[TableA_TableB](
    [aID] [int] NOT NULL,
    [bID] [int] NOT NULL,
 CONSTRAINT [PK_Group_Module] PRIMARY KEY CLUSTERED
(
    [aID]] ASC,
    [bID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

ALTER TABLE [dbo].[TableA_TableB]  WITH CHECK ADD  CONSTRAINT [FK_TableA_TableB_TableA] FOREIGN KEY([aID])])
REFERENCES [dbo].[Group] ([aID])

ALTER TABLE [dbo].[TableA_TableB]  WITH CHECK ADD  CONSTRAINT [FK_TableA_TableB_TableB] FOREIGN KEY([bID])
REFERENCES [dbo].[Module] ([bID])

Diese möchte ich quasi folgendermaßen in meinem Grid anzeigen:

Code:
SELECT a.[aID]
      ,a.[aName]
      ,b.[bID]
      ,b.[bName]
FROM [Database0].[dbo].[TableA] as a
LEFT JOIN [Database0].[dbo].[TableA_TableB] as ab ON a.[aID] = ab.[aID]
LEFT JOIN [Database0].[dbo].[TableB] as b ON ab.[bID] = m.[bID]
Code:
SELECT a.[aID]
,a.[aName]
,b.[bID]
,b.[bName]
FROM [Database0].[dbo].[TableA] as a
LEFT JOIN [Database0].[dbo].[TableA_TableB] as ab ON a.[aID] = ab.[aID]
LEFT JOIN [Database0].[dbo].[TableB] as b ON ab.[bID] = m.[bID]
Code:
SELECT a.[aID]
      ,a.[aName]
      ,b.[bID]
      ,b.[bName]
FROM [Database0].[dbo].[TableA] as a
LEFT JOIN [Database0].[dbo].[TableA_TableB] as ab ON a.[aID] = ab.[aID]
LEFT JOIN [Database0].[dbo].[TableB] as b ON ab.[bID] = m.[bID]


D.h. generell möchte ich jedes Vorkommen von TabelleA auch anzeigen, selbst wenn keine TabelleB in TabelleA_TabelleB dazu vorhanden ist.
Ist eine TabelleB vorhanden, möchte ich alle Vorkommen von TabellB im Eintrag unter dem Eintrag zu TabelleA in einem separierten DataGrid anzeigen.

Es wäre wirklich super, wenn mir jemand den letzten entscheidenden Hinweis geben könnte ;-)


PS:
Der XAML-Code dazu sieht momentan wie folgt aus:
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
1
2
3
4
5
6
7
8
9
10
11
12
13
14
  <Grid x:Name="LayoutRoot">
        <sdk:DataGrid AutoGenerateColumns="True" Margin="10" Name="dataGridTableA" ItemsSource="{Binding ElementName=tableADomainDataSource, Path=Data}">
            <sdk:DataGrid.RowDetailsTemplate>
                <DataTemplate>
                    <sdk:DataGrid Name="dataGridTableB" AutoGenerateColumns="True" ItemsSource="{Binding TableBs}"/>
                </DataTemplate>
            </sdk:DataGrid.RowDetailsTemplate>
        </sdk:DataGrid>
        <riaControls:DomainDataSource AutoLoad="True" d:DesignData="{d:DesignInstance model:TableA, CreateList=true}" Height="0" LoadedData="tableADomainDataSource_LoadedData" Name="tableADomainDataSource" QueryName="GetTableAsQuery" Width="0">
            <riaControls:DomainDataSource.DomainContext>
                <my:Database0DomainContext />
            </riaControls:DomainDataSource.DomainContext>
        </riaControls:DomainDataSource>
    </Grid>
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<Grid x:Name="LayoutRoot">
<sdk:DataGrid AutoGenerateColumns="True" Margin="10" Name="dataGridTableA" ItemsSource="{Binding ElementName=tableADomainDataSource, Path=Data}">
<sdk:DataGrid.RowDetailsTemplate>
<DataTemplate>
<sdk:DataGrid Name="dataGridTableB" AutoGenerateColumns="True" ItemsSource="{Binding TableBs}"/>
</DataTemplate>
</sdk:DataGrid.RowDetailsTemplate>
</sdk:DataGrid>
<riaControls:DomainDataSource AutoLoad="True" d:DesignData="{d:DesignInstance model:TableA, CreateList=true}" Height="0" LoadedData="tableADomainDataSource_LoadedData" Name="tableADomainDataSource" QueryName="GetTableAsQuery" Width="0">
<riaControls:DomainDataSource.DomainContext>
<my:Database0DomainContext />
</riaControls:DomainDataSource.DomainContext>
</riaControls:DomainDataSource>
</Grid>
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
  <Grid x:Name="LayoutRoot">
        <sdk:DataGrid AutoGenerateColumns="True" Margin="10" Name="dataGridTableA" ItemsSource="{Binding ElementName=tableADomainDataSource, Path=Data}">
            <sdk:DataGrid.RowDetailsTemplate>
                <DataTemplate>
                    <sdk:DataGrid Name="dataGridTableB" AutoGenerateColumns="True" ItemsSource="{Binding TableBs}"/>
                </DataTemplate>
            </sdk:DataGrid.RowDetailsTemplate>
        </sdk:DataGrid>
        <riaControls:DomainDataSource AutoLoad="True" d:DesignData="{d:DesignInstance model:TableA, CreateList=true}" Height="0" LoadedData="tableADomainDataSource_LoadedData" Name="tableADomainDataSource" QueryName="GetTableAsQuery" Width="0">
            <riaControls:DomainDataSource.DomainContext>
                <my:Database0DomainContext />
            </riaControls:DomainDataSource.DomainContext>
        </riaControls:DomainDataSource>
    </Grid>


C# Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
private void tableADomainDataSource_LoadedData(object sender, System.Windows.Controls.LoadedDataEventArgs e)
{
    var first = e.Entities.First() as BusinessApplication1.Web.Models.tableA;
    var query = from tableB in first.TableBs select tableB;

    System.Windows.MessageBox.Show(first.Name);
    System.Windows.MessageBox.Show(query.Count().ToString());
    foreach (BusinessApplication1.Web.Models.TableB tableB in query)
    {
        System.Windows.MessageBox.Show(tableB.Name);
    }
           
    if (e.HasError)
    {
        System.Windows.MessageBox.Show(e.Error.ToString(), "Load Error", System.Windows.MessageBoxButton.OK);
        e.MarkErrorAsHandled();
    }
}
C# Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
private void tableADomainDataSource_LoadedData(object sender, System.Windows.Controls.LoadedDataEventArgs e)
{
var first = e.Entities.First() as BusinessApplication1.Web.Models.tableA;
var query = from tableB in first.TableBs select tableB;

System.Windows.MessageBox.Show(first.Name);
System.Windows.MessageBox.Show(query.Count().ToString());
foreach (BusinessApplication1.Web.Models.TableB tableB in query)
{
System.Windows.MessageBox.Show(tableB.Name);
}

if (e.HasError)
{
System.Windows.MessageBox.Show(e.Error.ToString(), "Load Error", System.Windows.MessageBoxButton.OK);
e.MarkErrorAsHandled();
}
}
C# Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
private void tableADomainDataSource_LoadedData(object sender, System.Windows.Controls.LoadedDataEventArgs e)
{
    var first = e.Entities.First() as BusinessApplication1.Web.Models.tableA;
    var query = from tableB in first.TableBs select tableB;

    System.Windows.MessageBox.Show(first.Name);
    System.Windows.MessageBox.Show(query.Count().ToString());
    foreach (BusinessApplication1.Web.Models.TableB tableB in query)
    {
        System.Windows.MessageBox.Show(tableB.Name);
    }
           
    if (e.HasError)
    {
        System.Windows.MessageBox.Show(e.Error.ToString(), "Load Error", System.Windows.MessageBoxButton.OK);
        e.MarkErrorAsHandled();
    }
}


Der Code im Loaded_Data - Ereignis fördert merkwürdigerweiße als Count() "0" zu Tage. Das kann eigentlich nicht sein. Die Tabellen sind momentan mit folgenden Werten gefüllt

Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
TabelleA (aID, aName):
1 aNameA
2 aNameB
3 aNameC

TabelleB (bID, bName):
1 bNameA
2 bNameB
3 bNameC
4 bNameD
5 bNameE
6 bNameF

TabbleA_TabelleB (aID, bID):
1 1
1 2
1 3
1 4
2 5
2 6
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
TabelleA (aID, aName):
1 aNameA
2 aNameB
3 aNameC

TabelleB (bID, bName):
1 bNameA
2 bNameB
3 bNameC
4 bNameD
5 bNameE
6 bNameF

TabbleA_TabelleB (aID, bID):
1 1
1 2
1 3
1 4
2 5
2 6
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
TabelleA (aID, aName):
1 aNameA
2 aNameB
3 aNameC

TabelleB (bID, bName):
1 bNameA
2 bNameB
3 bNameC
4 bNameD
5 bNameE
6 bNameF

TabbleA_TabelleB (aID, bID):
1 1
1 2
1 3
1 4
2 5
2 6


Zuletzt bearbeitet von FrEEzE2046 am 17:26:19 30.08.2010, insgesamt 2-mal bearbeitet
witte
Mitglied

Benutzerprofil
Anmeldungsdatum: 08.01.2008
Beiträge: 1295
Beitrag witte Mitglied 18:41:44 30.08.2010   Titel:              Zitieren

Auch wenn du es mit anderen Worten ausdrücken willst bleibt es dabei. Du mußt einen Graphen mit Include() erzeugen bei denen die referenzierten B's in einer Liste an die A's hängen.
FrEEzE2046 schrieb:
Der Code im Loaded_Data - Ereignis fördert merkwürdigerwei<b>s</b>e als Count() "0" zu Tage. Das kann eigentlich nicht sein.
Warum nicht? Die B's sind doch noch gar nicht geladen. Hat das erste TableA überhaupt B-Subobjekte? Vorausgesetzt es handelt sich bei first um das erste TableA-objekt in deinem TableA-Set. Du kannst alternativ ein
C# Code:
var first = e.Entities.First() as BusinessApplication1.Web.Models.tableA;
first.TableBs.Load();
var query = from tableB in first.TableBs select tableB;
C# Code:
var first = e.Entities.First() as BusinessApplication1.Web.Models.tableA;
first.TableBs.Load();
var query = from tableB in first.TableBs select tableB;
C# Code:
var first = e.Entities.First() as BusinessApplication1.Web.Models.tableA;
first.TableBs.Load();
var query = from tableB in first.TableBs select tableB;
versuchen, aber Deferred Loading ist in diesem Fall recht teuer, weil er für jedes A nochmal einen Roundtrip zur Datenbank machen muss.
FrEEzE2046
Mitglied

Benutzerprofil
Anmeldungsdatum: 03.12.2008
Beiträge: 786
Beitrag FrEEzE2046 Mitglied 19:33:43 30.08.2010   Titel:              Zitieren

Was genau muss ich denn in den string der als Parameter von Include() erwartet wird schreiben? Den Namen des Navigation Propertys?
FrEEzE2046
Mitglied

Benutzerprofil
Anmeldungsdatum: 03.12.2008
Beiträge: 786
Beitrag FrEEzE2046 Mitglied 21:07:50 30.08.2010   Titel:              Zitieren

Ich hab es nun folgendermaßen gemacht:
C# Code:
public IQueryable<TableA> GetTableAs()
{
    return this.ObjectContext.TableAs.Include("TableBs");
}
C# Code:
public IQueryable<TableA> GetTableAs()
{
return this.ObjectContext.TableAs.Include("TableBs");
}
C# Code:
public IQueryable<TableA> GetTableAs()
{
    return this.ObjectContext.TableAs.Include("TableBs");
}


Leider führt das zu einem merkwürdigen Ergebnis. Ich bekomme folgende Zuordnung heraus:

aID 1 enthält bID 1
aID 2 enthält bID 2
aID 3 enthält bID 3
usw.


Zuletzt bearbeitet von FrEEzE2046 am 21:08:13 30.08.2010, insgesamt 1-mal bearbeitet
witte
Mitglied

Benutzerprofil
Anmeldungsdatum: 08.01.2008
Beiträge: 1295
Beitrag witte Mitglied 13:07:41 31.08.2010   Titel:              Zitieren

Also ich habe das jetzt mal in einem Konsolenanwendung nachvollzogen. Allerdings nicht über ria sondern klassisch.

Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[TableB](
    [bID] [int] IDENTITY(1,1) NOT NULL,
    [bName] [varchar](32) NOT NULL,
 CONSTRAINT [PK_bID] PRIMARY KEY CLUSTERED
(
    [bID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

CREATE TABLE [dbo].[TableA](
    [aID] [int] IDENTITY(1,1) NOT NULL,
    [aName] [varchar](32) NOT NULL,
 CONSTRAINT [PK_aID] PRIMARY KEY CLUSTERED
(
    [aID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

CREATE TABLE [dbo].[TableA_TableB](
    [aID] [int] NOT NULL,
    [bID] [int] NOT NULL,
 CONSTRAINT [PK_Group_Module] PRIMARY KEY CLUSTERED
(
    [aID] ASC,
    [bID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
ALTER TABLE [dbo].[TableA_TableB]  WITH CHECK ADD  CONSTRAINT [FK_TableA_TableB_TableA] FOREIGN KEY([aID])
REFERENCES [dbo].[TableA] ([aID])
GO
ALTER TABLE [dbo].[TableA_TableB] CHECK CONSTRAINT [FK_TableA_TableB_TableA]
GO
ALTER TABLE [dbo].[TableA_TableB]  WITH CHECK ADD  CONSTRAINT [FK_TableA_TableB_TableB] FOREIGN KEY([bID])
REFERENCES [dbo].[TableB] ([bID])
GO
ALTER TABLE [dbo].[TableA_TableB] CHECK CONSTRAINT [FK_TableA_TableB_TableB]
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[TableB](
[bID] [int] IDENTITY(1,1) NOT NULL,
[bName] [varchar](32) NOT NULL,
CONSTRAINT [PK_bID] PRIMARY KEY CLUSTERED
(
[bID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

CREATE TABLE [dbo].[TableA](
[aID] [int] IDENTITY(1,1) NOT NULL,
[aName] [varchar](32) NOT NULL,
CONSTRAINT [PK_aID] PRIMARY KEY CLUSTERED
(
[aID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

CREATE TABLE [dbo].[TableA_TableB](
[aID] [int] NOT NULL,
[bID] [int] NOT NULL,
CONSTRAINT [PK_Group_Module] PRIMARY KEY CLUSTERED
(
[aID] ASC,
[bID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
ALTER TABLE [dbo].[TableA_TableB] WITH CHECK ADD CONSTRAINT [FK_TableA_TableB_TableA] FOREIGN KEY([aID])
REFERENCES [dbo].[TableA] ([aID])
GO
ALTER TABLE [dbo].[TableA_TableB] CHECK CONSTRAINT [FK_TableA_TableB_TableA]
GO
ALTER TABLE [dbo].[TableA_TableB] WITH CHECK ADD CONSTRAINT [FK_TableA_TableB_TableB] FOREIGN KEY([bID])
REFERENCES [dbo].[TableB] ([bID])
GO
ALTER TABLE [dbo].[TableA_TableB] CHECK CONSTRAINT [FK_TableA_TableB_TableB]
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[TableB](
    [bID] [int] IDENTITY(1,1) NOT NULL,
    [bName] [varchar](32) NOT NULL,
 CONSTRAINT [PK_bID] PRIMARY KEY CLUSTERED
(
    [bID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

CREATE TABLE [dbo].[TableA](
    [aID] [int] IDENTITY(1,1) NOT NULL,
    [aName] [varchar](32) NOT NULL,
 CONSTRAINT [PK_aID] PRIMARY KEY CLUSTERED
(
    [aID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

CREATE TABLE [dbo].[TableA_TableB](
    [aID] [int] NOT NULL,
    [bID] [int] NOT NULL,
 CONSTRAINT [PK_Group_Module] PRIMARY KEY CLUSTERED
(
    [aID] ASC,
    [bID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
ALTER TABLE [dbo].[TableA_TableB]  WITH CHECK ADD  CONSTRAINT [FK_TableA_TableB_TableA] FOREIGN KEY([aID])
REFERENCES [dbo].[TableA] ([aID])
GO
ALTER TABLE [dbo].[TableA_TableB] CHECK CONSTRAINT [FK_TableA_TableB_TableA]
GO
ALTER TABLE [dbo].[TableA_TableB]  WITH CHECK ADD  CONSTRAINT [FK_TableA_TableB_TableB] FOREIGN KEY([bID])
REFERENCES [dbo].[TableB] ([bID])
GO
ALTER TABLE [dbo].[TableA_TableB] CHECK CONSTRAINT [FK_TableA_TableB_TableB]


Dann habe ich ein Entity Data Model hinzugefügt und dort die beiden Tabellen importiert. Das XML was automatisch generiert wird)
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?xml version="1.0" encoding="utf-8"?>
<edmx:Edmx Version="2.0" xmlns:edmx="http://schemas.microsoft.com/ado/2008/10/edmx">
  <!-- EF Runtime content -->
  <edmx:Runtime>
    <!-- SSDL content -->
    <edmx:StorageModels>
      <Schema Namespace="TestModel.Store" Alias="Self" Provider="System.Data.SqlClient" ProviderManifestToken="2005" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2009/02/edm/ssdl">
        <EntityContainer Name="TestModelStoreContainer">
          <EntitySet Name="TableA" EntityType="TestModel.Store.TableA" store:Type="Tables" Schema="dbo" />
          <EntitySet Name="TableA_TableB" EntityType="TestModel.Store.TableA_TableB" store:Type="Tables" Schema="dbo" />
          <EntitySet Name="TableB" EntityType="TestModel.Store.TableB" store:Type="Tables" Schema="dbo" />
          <AssociationSet Name="FK_TableA_TableB_TableA" Association="TestModel.Store.FK_TableA_TableB_TableA">
            <End Role="TableA" EntitySet="TableA" />
            <End Role="TableA_TableB" EntitySet="TableA_TableB" />
          </AssociationSet>
          <AssociationSet Name="FK_TableA_TableB_TableB" Association="TestModel.Store.FK_TableA_TableB_TableB">
            <End Role="TableB" EntitySet="TableB" />
            <End Role="TableA_TableB" EntitySet="TableA_TableB" />
          </AssociationSet>
        </EntityContainer>
        <EntityType Name="TableA">
          <Key>
            <PropertyRef Name="aID" />
          </Key>
          <Property Name="aID" Type="int" Nullable="false" StoreGeneratedPattern="Identity" />
          <Property Name="aName" Type="varchar" Nullable="false" MaxLength="32" />
        </EntityType>
        <EntityType Name="TableA_TableB">
          <Key>
            <PropertyRef Name="aID" />
            <PropertyRef Name="bID" />
          </Key>
          <Property Name="aID" Type="int" Nullable="false" />
          <Property Name="bID" Type="int" Nullable="false" />
        </EntityType>
        <EntityType Name="TableB">
          <Key>
            <PropertyRef Name="bID" />
          </Key>
          <Property Name="bID" Type="int" Nullable="false" StoreGeneratedPattern="Identity" />
          <Property Name="bName" Type="varchar" Nullable="false" MaxLength="32" />
        </EntityType>
        <Association Name="FK_TableA_TableB_TableA">
          <End Role="TableA" Type="TestModel.Store.TableA" Multiplicity="1" />
          <End Role="TableA_TableB" Type="TestModel.Store.TableA_TableB" Multiplicity="*" />
          <ReferentialConstraint>
            <Principal Role="TableA">
              <PropertyRef Name="aID" />
            </Principal>
            <Dependent Role="TableA_TableB">
              <PropertyRef Name="aID" />
            </Dependent>
          </ReferentialConstraint>
        </Association>
        <Association Name="FK_TableA_TableB_TableB">
          <End Role="TableB" Type="TestModel.Store.TableB" Multiplicity="1" />
          <End Role="TableA_TableB" Type="TestModel.Store.TableA_TableB" Multiplicity="*" />
          <ReferentialConstraint>
            <Principal Role="TableB">
              <PropertyRef Name="bID" />
            </Principal>
            <Dependent Role="TableA_TableB">
              <PropertyRef Name="bID" />
            </Dependent>
          </ReferentialConstraint>
        </Association>
      </Schema>
    </edmx:StorageModels>
    <!-- CSDL content -->
    <edmx:ConceptualModels>
      <Schema Namespace="TestModel" Alias="Self" xmlns:annotation="http://schemas.microsoft.com/ado/2009/02/edm/annotation" xmlns="http://schemas.microsoft.com/ado/2008/09/edm">
        <EntityContainer Name="TestEntities" annotation:LazyLoadingEnabled="true">
          <EntitySet Name="TableAs" EntityType="TestModel.TableA" />
          <EntitySet Name="TableBs" EntityType="TestModel.TableB" />
          <AssociationSet Name="TableA_TableB" Association="TestModel.TableA_TableB">
            <End Role="TableA" EntitySet="TableAs" />
            <End Role="TableB" EntitySet="TableBs" />
          </AssociationSet>
        </EntityContainer>
        <EntityType Name="TableA">
          <Key>
            <PropertyRef Name="aID" />
          </Key>
          <Property Name="aID" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
          <Property Name="aName" Type="String" Nullable="false" MaxLength="32" Unicode="false" FixedLength="false" />
          <NavigationProperty Name="TableBs" Relationship="TestModel.TableA_TableB" FromRole="TableA" ToRole="TableB" />
        </EntityType>
        <EntityType Name="TableB">
          <Key>
            <PropertyRef Name="bID" />
          </Key>
          <Property Name="bID" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
          <Property Name="bName" Type="String" Nullable="false" MaxLength="32" Unicode="false" FixedLength="false" />
          <NavigationProperty Name="TableAs" Relationship="TestModel.TableA_TableB" FromRole="TableB" ToRole="TableA" />
        </EntityType>
        <Association Name="TableA_TableB">
          <End Role="TableA" Type="TestModel.TableA" Multiplicity="*" />
          <End Role="TableB" Type="TestModel.TableB" Multiplicity="*" />
        </Association>
      </Schema>
    </edmx:ConceptualModels>
    <!-- C-S mapping content -->
    <edmx:Mappings>
      <Mapping Space="C-S" xmlns="http://schemas.microsoft.com/ado/2008/09/mapping/cs">
        <EntityContainerMapping StorageEntityContainer="TestModelStoreContainer" CdmEntityContainer="TestEntities">
          <EntitySetMapping Name="TableAs"><EntityTypeMapping TypeName="TestModel.TableA"><MappingFragment StoreEntitySet="TableA">
            <ScalarProperty Name="aID" ColumnName="aID" />
            <ScalarProperty Name="aName" ColumnName="aName" />
          </MappingFragment></EntityTypeMapping></EntitySetMapping>
          <EntitySetMapping Name="TableBs"><EntityTypeMapping TypeName="TestModel.TableB"><MappingFragment StoreEntitySet="TableB">
            <ScalarProperty Name="bID" ColumnName="bID" />
            <ScalarProperty Name="bName" ColumnName="bName" />
          </MappingFragment></EntityTypeMapping></EntitySetMapping>
          <AssociationSetMapping Name="TableA_TableB" TypeName="TestModel.TableA_TableB" StoreEntitySet="TableA_TableB">
            <EndProperty Name="TableA">
              <ScalarProperty Name="aID" ColumnName="aID" />
            </EndProperty>
            <EndProperty Name="TableB">
              <ScalarProperty Name="bID" ColumnName="bID" />
            </EndProperty>
          </AssociationSetMapping>
        </EntityContainerMapping>
      </Mapping>
    </edmx:Mappings>
  </edmx:Runtime>
  <!-- EF Designer content (DO NOT EDIT MANUALLY BELOW HERE) -->
  <Designer xmlns="http://schemas.microsoft.com/ado/2008/10/edmx">
    <Connection>
      <DesignerInfoPropertySet>
        <DesignerProperty Name="MetadataArtifactProcessing" Value="EmbedInOutputAssembly" />
      </DesignerInfoPropertySet>
    </Connection>
    <Options>
      <DesignerInfoPropertySet>
        <DesignerProperty Name="ValidateOnBuild" Value="true" />
        <DesignerProperty Name="EnablePluralization" Value="False" />
        <DesignerProperty Name="IncludeForeignKeysInModel" Value="True" />
      </DesignerInfoPropertySet>
    </Options>
    <!-- Diagram content (shape and connector positions) -->
    <Diagrams>
      <Diagram Name="Model1">
        <EntityTypeShape EntityType="TestModel.TableA" Width="1.5" PointX="0.75" PointY="0.875" Height="1.427958984375" IsExpanded="true" />
        <EntityTypeShape EntityType="TestModel.TableB" Width="1.5" PointX="3" PointY="0.875" Height="1.4279589843749996" IsExpanded="true" />
        <AssociationConnector Association="TestModel.TableA_TableB" ManuallyRouted="false">
          <ConnectorPoint PointX="2.25" PointY="1.5889794921874998" />
          <ConnectorPoint PointX="3" PointY="1.5889794921874998" />
        </AssociationConnector>
      </Diagram>
    </Diagrams>
  </Designer>
</edmx:Edmx>
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?xml version="1.0" encoding="utf-8"?>
<edmx:Edmx Version="2.0" xmlns:edmx="http://schemas.microsoft.com/ado/2008/10/edmx">
<!-- EF Runtime content -->
<edmx:Runtime>
<!-- SSDL content -->
<edmx:StorageModels>
<Schema Namespace="TestModel.Store" Alias="Self" Provider="System.Data.SqlClient" ProviderManifestToken="2005" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2009/02/edm/ssdl">
<EntityContainer Name="TestModelStoreContainer">
<EntitySet Name="TableA" EntityType="TestModel.Store.TableA" store:Type="Tables" Schema="dbo" />
<EntitySet Name="TableA_TableB" EntityType="TestModel.Store.TableA_TableB" store:Type="Tables" Schema="dbo" />
<EntitySet Name="TableB" EntityType="TestModel.Store.TableB" store:Type="Tables" Schema="dbo" />
<AssociationSet Name="FK_TableA_TableB_TableA" Association="TestModel.Store.FK_TableA_TableB_TableA">
<End Role="TableA" EntitySet="TableA" />
<End Role="TableA_TableB" EntitySet="TableA_TableB" />
</AssociationSet>
<AssociationSet Name="FK_TableA_TableB_TableB" Association="TestModel.Store.FK_TableA_TableB_TableB">
<End Role="TableB" EntitySet="TableB" />
<End Role="TableA_TableB" EntitySet="TableA_TableB" />
</AssociationSet>
</EntityContainer>
<EntityType Name="TableA">
<Key>
<PropertyRef Name="aID" />
</Key>
<Property Name="aID" Type="int" Nullable="false" StoreGeneratedPattern="Identity" />
<Property Name="aName" Type="varchar" Nullable="false" MaxLength="32" />
</EntityType>
<EntityType Name="TableA_TableB">
<Key>
<PropertyRef Name="aID" />
<PropertyRef Name="bID" />
</Key>
<Property Name="aID" Type="int" Nullable="false" />
<Property Name="bID" Type="int" Nullable="false" />
</EntityType>
<EntityType Name="TableB">
<Key>
<PropertyRef Name="bID" />
</Key>
<Property Name="bID" Type="int" Nullable="false" StoreGeneratedPattern="Identity" />
<Property Name="bName" Type="varchar" Nullable="false" MaxLength="32" />
</EntityType>
<Association Name="FK_TableA_TableB_TableA">
<End Role="TableA" Type="TestModel.Store.TableA" Multiplicity="1" />
<End Role="TableA_TableB" Type="TestModel.Store.TableA_TableB" Multiplicity="*" />
<ReferentialConstraint>
<Principal Role="TableA">
<PropertyRef Name="aID" />
</Principal>
<Dependent Role="TableA_TableB">
<PropertyRef Name="aID" />
</Dependent>
</ReferentialConstraint>
</Association>
<Association Name="FK_TableA_TableB_TableB">
<End Role="TableB" Type="TestModel.Store.TableB" Multiplicity="1" />
<End Role="TableA_TableB" Type="TestModel.Store.TableA_TableB" Multiplicity="*" />
<ReferentialConstraint>
<Principal Role="TableB">
<PropertyRef Name="bID" />
</Principal>
<Dependent Role="TableA_TableB">
<PropertyRef Name="bID" />
</Dependent>
</ReferentialConstraint>
</Association>
</Schema>
</edmx:StorageModels>
<!-- CSDL content -->
<edmx:ConceptualModels>
<Schema Namespace="TestModel" Alias="Self" xmlns:annotation="http://schemas.microsoft.com/ado/2009/02/edm/annotation" xmlns="http://schemas.microsoft.com/ado/2008/09/edm">
<EntityContainer Name="TestEntities" annotation:LazyLoadingEnabled="true">
<EntitySet Name="TableAs" EntityType="TestModel.TableA" />
<EntitySet Name="TableBs" EntityType="TestModel.TableB" />
<AssociationSet Name="TableA_TableB" Association="TestModel.TableA_TableB">
<End Role="TableA" EntitySet="TableAs" />
<End Role="TableB" EntitySet="TableBs" />
</AssociationSet>
</EntityContainer>
<EntityType Name="TableA">
<Key>
<PropertyRef Name="aID" />
</Key>
<Property Name="aID" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
<Property Name="aName" Type="String" Nullable="false" MaxLength="32" Unicode="false" FixedLength="false" />
<NavigationProperty Name="TableBs" Relationship="TestModel.TableA_TableB" FromRole="TableA" ToRole="TableB" />
</EntityType>
<EntityType Name="TableB">
<Key>
<PropertyRef Name="bID" />
</Key>
<Property Name="bID" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
<Property Name="bName" Type="String" Nullable="false" MaxLength="32" Unicode="false" FixedLength="false" />
<NavigationProperty Name="TableAs" Relationship="TestModel.TableA_TableB" FromRole="TableB" ToRole="TableA" />
</EntityType>
<Association Name="TableA_TableB">
<End Role="TableA" Type="TestModel.TableA" Multiplicity="*" />
<End Role="TableB" Type="TestModel.TableB" Multiplicity="*" />
</Association>
</Schema>
</edmx:ConceptualModels>
<!-- C-S mapping content -->
<edmx:Mappings>
<Mapping Space="C-S" xmlns="http://schemas.microsoft.com/ado/2008/09/mapping/cs">
<EntityContainerMapping StorageEntityContainer="TestModelStoreContainer" CdmEntityContainer="TestEntities">
<EntitySetMapping Name="TableAs"><EntityTypeMapping TypeName="TestModel.TableA"><MappingFragment StoreEntitySet="TableA">
<ScalarProperty Name="aID" ColumnName="aID" />
<ScalarProperty Name="aName" ColumnName="aName" />
</MappingFragment></EntityTypeMapping></EntitySetMapping>
<EntitySetMapping Name="TableBs"><EntityTypeMapping TypeName="TestModel.TableB"><MappingFragment StoreEntitySet="TableB">
<ScalarProperty Name="bID" ColumnName="bID" />
<ScalarProperty Name="bName" ColumnName="bName" />
</MappingFragment></EntityTypeMapping></EntitySetMapping>
<AssociationSetMapping Name="TableA_TableB" TypeName="TestModel.TableA_TableB" StoreEntitySet="TableA_TableB">
<EndProperty Name="TableA">
<ScalarProperty Name="aID" ColumnName="aID" />
</EndProperty>
<EndProperty Name="TableB">
<ScalarProperty Name="bID" ColumnName="bID" />
</EndProperty>
</AssociationSetMapping>
</EntityContainerMapping>
</Mapping>
</edmx:Mappings>
</edmx:Runtime>
<!-- EF Designer content (DO NOT EDIT MANUALLY BELOW HERE) -->
<Designer xmlns="http://schemas.microsoft.com/ado/2008/10/edmx">
<Connection>
<DesignerInfoPropertySet>
<DesignerProperty Name="MetadataArtifactProcessing" Value="EmbedInOutputAssembly" />
</DesignerInfoPropertySet>
</Connection>
<Options>
<DesignerInfoPropertySet>
<DesignerProperty Name="ValidateOnBuild" Value="true" />
<DesignerProperty Name="EnablePluralization" Value="False" />
<DesignerProperty Name="IncludeForeignKeysInModel" Value="True" />
</DesignerInfoPropertySet>
</Options>
<!-- Diagram content (shape and connector positions) -->
<Diagrams>
<Diagram Name="Model1">
<EntityTypeShape EntityType="TestModel.TableA" Width="1.5" PointX="0.75" PointY="0.875" Height="1.427958984375" IsExpanded="true" />
<EntityTypeShape EntityType="TestModel.TableB" Width="1.5" PointX="3" PointY="0.875" Height="1.4279589843749996" IsExpanded="true" />
<AssociationConnector Association="TestModel.TableA_TableB" ManuallyRouted="false">
<ConnectorPoint PointX="2.25" PointY="1.5889794921874998" />
<ConnectorPoint PointX="3" PointY="1.5889794921874998" />
</AssociationConnector>
</Diagram>
</Diagrams>
</Designer>
</edmx:Edmx>
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?xml version="1.0" encoding="utf-8"?>
<edmx:Edmx Version="2.0" xmlns:edmx="http://schemas.microsoft.com/ado/2008/10/edmx">
  <!-- EF Runtime content -->
  <edmx:Runtime>
    <!-- SSDL content -->
    <edmx:StorageModels>
      <Schema Namespace="TestModel.Store" Alias="Self" Provider="System.Data.SqlClient" ProviderManifestToken="2005" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2009/02/edm/ssdl">
        <EntityContainer Name="TestModelStoreContainer">
          <EntitySet Name="TableA" EntityType="TestModel.Store.TableA" store:Type="Tables" Schema="dbo" />
          <EntitySet Name="TableA_TableB" EntityType="TestModel.Store.TableA_TableB" store:Type="Tables" Schema="dbo" />
          <EntitySet Name="TableB" EntityType="TestModel.Store.TableB" store:Type="Tables" Schema="dbo" />
          <AssociationSet Name="FK_TableA_TableB_TableA" Association="TestModel.Store.FK_TableA_TableB_TableA">
            <End Role="TableA" EntitySet="TableA" />
            <End Role="TableA_TableB" EntitySet="TableA_TableB" />
          </AssociationSet>
          <AssociationSet Name="FK_TableA_TableB_TableB" Association="TestModel.Store.FK_TableA_TableB_TableB">
            <End Role="TableB" EntitySet="TableB" />
            <End Role="TableA_TableB" EntitySet="TableA_TableB" />
          </AssociationSet>
        </EntityContainer>
        <EntityType Name="TableA">
          <Key>
            <PropertyRef Name="aID" />
          </Key>
          <Property Name="aID" Type="int" Nullable="false" StoreGeneratedPattern="Identity" />
          <Property Name="aName" Type="varchar" Nullable="false" MaxLength="32" />
        </EntityType>
        <EntityType Name="TableA_TableB">
          <Key>
            <PropertyRef Name="aID" />
            <PropertyRef Name="bID" />
          </Key>
          <Property Name="aID" Type="int" Nullable="false" />
          <Property Name="bID" Type="int" Nullable="false" />
        </EntityType>
        <EntityType Name="TableB">
          <Key>
            <PropertyRef Name="bID" />
          </Key>
          <Property Name="bID" Type="int" Nullable="false" StoreGeneratedPattern="Identity" />
          <Property Name="bName" Type="varchar" Nullable="false" MaxLength="32" />
        </EntityType>
        <Association Name="FK_TableA_TableB_TableA">
          <End Role="TableA" Type="TestModel.Store.TableA" Multiplicity="1" />
          <End Role="TableA_TableB" Type="TestModel.Store.TableA_TableB" Multiplicity="*" />
          <ReferentialConstraint>
            <Principal Role="TableA">
              <PropertyRef Name="aID" />
            </Principal>
            <Dependent Role="TableA_TableB">
              <PropertyRef Name="aID" />
            </Dependent>
          </ReferentialConstraint>
        </Association>
        <Association Name="FK_TableA_TableB_TableB">
          <End Role="TableB" Type="TestModel.Store.TableB" Multiplicity="1" />
          <End Role="TableA_TableB" Type="TestModel.Store.TableA_TableB" Multiplicity="*" />
          <ReferentialConstraint>
            <Principal Role="TableB">
              <PropertyRef Name="bID" />
            </Principal>
            <Dependent Role="TableA_TableB">
              <PropertyRef Name="bID" />
            </Dependent>
          </ReferentialConstraint>
        </Association>
      </Schema>
    </edmx:StorageModels>
    <!-- CSDL content -->
    <edmx:ConceptualModels>
      <Schema Namespace="TestModel" Alias="Self" xmlns:annotation="http://schemas.microsoft.com/ado/2009/02/edm/annotation" xmlns="http://schemas.microsoft.com/ado/2008/09/edm">
        <EntityContainer Name="TestEntities" annotation:LazyLoadingEnabled="true">
          <EntitySet Name="TableAs" EntityType="TestModel.TableA" />
          <EntitySet Name="TableBs" EntityType="TestModel.TableB" />
          <AssociationSet Name="TableA_TableB" Association="TestModel.TableA_TableB">
            <End Role="TableA" EntitySet="TableAs" />
            <End Role="TableB" EntitySet="TableBs" />
          </AssociationSet>
        </EntityContainer>
        <EntityType Name="TableA">
          <Key>
            <PropertyRef Name="aID" />
          </Key>
          <Property Name="aID" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
          <Property Name="aName" Type="String" Nullable="false" MaxLength="32" Unicode="false" FixedLength="false" />
          <NavigationProperty Name="TableBs" Relationship="TestModel.TableA_TableB" FromRole="TableA" ToRole="TableB" />
        </EntityType>
        <EntityType Name="TableB">
          <Key>
            <PropertyRef Name="bID" />
          </Key>
          <Property Name="bID" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
          <Property Name="bName" Type="String" Nullable="false" MaxLength="32" Unicode="false" FixedLength="false" />
          <NavigationProperty Name="TableAs" Relationship="TestModel.TableA_TableB" FromRole="TableB" ToRole="TableA" />
        </EntityType>
        <Association Name="TableA_TableB">
          <End Role="TableA" Type="TestModel.TableA" Multiplicity="*" />
          <End Role="TableB" Type="TestModel.TableB" Multiplicity="*" />
        </Association>
      </Schema>
    </edmx:ConceptualModels>
    <!-- C-S mapping content -->
    <edmx:Mappings>
      <Mapping Space="C-S" xmlns="http://schemas.microsoft.com/ado/2008/09/mapping/cs">
        <EntityContainerMapping StorageEntityContainer="TestModelStoreContainer" CdmEntityContainer="TestEntities">
          <EntitySetMapping Name="TableAs"><EntityTypeMapping TypeName="TestModel.TableA"><MappingFragment StoreEntitySet="TableA">
            <ScalarProperty Name="aID" ColumnName="aID" />
            <ScalarProperty Name="aName" ColumnName="aName" />
          </MappingFragment></EntityTypeMapping></EntitySetMapping>
          <EntitySetMapping Name="TableBs"><EntityTypeMapping TypeName="TestModel.TableB"><MappingFragment StoreEntitySet="TableB">
            <ScalarProperty Name="bID" ColumnName="bID" />
            <ScalarProperty Name="bName" ColumnName="bName" />
          </MappingFragment></EntityTypeMapping></EntitySetMapping>
          <AssociationSetMapping Name="TableA_TableB" TypeName="TestModel.TableA_TableB" StoreEntitySet="TableA_TableB">
            <EndProperty Name="TableA">
              <ScalarProperty Name="aID" ColumnName="aID" />
            </EndProperty>
            <EndProperty Name="TableB">
              <ScalarProperty Name="bID" ColumnName="bID" />
            </EndProperty>
          </AssociationSetMapping>
        </EntityContainerMapping>
      </Mapping>
    </edmx:Mappings>
  </edmx:Runtime>
  <!-- EF Designer content (DO NOT EDIT MANUALLY BELOW HERE) -->
  <Designer xmlns="http://schemas.microsoft.com/ado/2008/10/edmx">
    <Connection>
      <DesignerInfoPropertySet>
        <DesignerProperty Name="MetadataArtifactProcessing" Value="EmbedInOutputAssembly" />
      </DesignerInfoPropertySet>
    </Connection>
    <Options>
      <DesignerInfoPropertySet>
        <DesignerProperty Name="ValidateOnBuild" Value="true" />
        <DesignerProperty Name="EnablePluralization" Value="False" />
        <DesignerProperty Name="IncludeForeignKeysInModel" Value="True" />
      </DesignerInfoPropertySet>
    </Options>
    <!-- Diagram content (shape and connector positions) -->
    <Diagrams>
      <Diagram Name="Model1">
        <EntityTypeShape EntityType="TestModel.TableA" Width="1.5" PointX="0.75" PointY="0.875" Height="1.427958984375" IsExpanded="true" />
        <EntityTypeShape EntityType="TestModel.TableB" Width="1.5" PointX="3" PointY="0.875" Height="1.4279589843749996" IsExpanded="true" />
        <AssociationConnector Association="TestModel.TableA_TableB" ManuallyRouted="false">
          <ConnectorPoint PointX="2.25" PointY="1.5889794921874998" />
          <ConnectorPoint PointX="3" PointY="1.5889794921874998" />
        </AssociationConnector>
      </Diagram>
    </Diagrams>
  </Designer>
</edmx:Edmx>


Dann der Code in der main
C# Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            ObservableCollection<TableA> entities;

            using (var ctx = new TestEntities()) {

                entities = new ObservableCollection<TableA>(ctx.TableAs.Include("TableBs"));
            }

            foreach (var tableA in entities) {

                Console.WriteLine(tableA.aName);

                foreach (var tableB in tableA.TableBs) {

                    Console.WriteLine("  " + tableB.bName);
                }
            }
        }
    }
}
C# Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{

ObservableCollection<TableA> entities;

using (var ctx = new TestEntities()) {

entities = new ObservableCollection<TableA>(ctx.TableAs.Include("TableBs"));
}

foreach (var tableA in entities) {

Console.WriteLine(tableA.aName);

foreach (var tableB in tableA.TableBs) {

Console.WriteLine(" " + tableB.bName);
}
}
}
}
}
C# Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            ObservableCollection<TableA> entities;

            using (var ctx = new TestEntities()) {

                entities = new ObservableCollection<TableA>(ctx.TableAs.Include("TableBs"));
            }

            foreach (var tableA in entities) {

                Console.WriteLine(tableA.aName);

                foreach (var tableB in tableA.TableBs) {

                    Console.WriteLine("  " + tableB.bName);
                }
            }
        }
    }
}


... gibt die gewünschten Beziehungen aus.
FrEEzE2046
Mitglied

Benutzerprofil
Anmeldungsdatum: 03.12.2008
Beiträge: 786
Beitrag FrEEzE2046 Mitglied 10:09:06 01.09.2010   Titel:              Zitieren

witte schrieb:
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{

ObservableCollection<TableA> entities;

using (var ctx = new TestEntities()) {

entities = new ObservableCollection<TableA>(ctx.TableAs.Include("TableBs"));
}

foreach (var tableA in entities) {

Console.WriteLine(tableA.aName);

foreach (var tableB in tableA.TableBs) {

Console.WriteLine(" " + tableB.bName);
}
}
}
}
}
[/cs]

... gibt die gewünschten Beziehungen aus.


Hi,

ich hab das jetzt mal exakt genau so gemacht wie du, nur eben innerhalb meines DomainServices. Die Beziehung zwischen TableA und TableB ist weiterhin aID == bID was natürlich absoluter Blödsinn ist.

Die Assoziation die gesetzt wurde, scheint für mich korrekt zu sein.


EDIT:
Okay, in einer Konsolen-Applikation bekomme ich nun auch die korrekte Beziehung ausgegeben. Offensichtlich liegt der Fehler im DomainService.

Ich habe dort in der Klasse von TableA folgendes definiert:
C# Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[MetadataTypeAttribute(typeof(TableA.TableAMetadata))]
public partial class TableA
{
    internal sealed class TableAMetadata
    {

        // Metadata classes are not meant to be instantiated.
        private TableAMetadata()
        {
        }

        public int aID { get; set; }

        [Association("TableA_TableB", "aID", "bID"), Include()]
        public EntityCollection<TableB> TableBs { get; set; }

        public string aName { get; set; }
    }
}
C# Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[MetadataTypeAttribute(typeof(TableA.TableAMetadata))]
public partial class TableA
{
internal sealed class TableAMetadata
{

// Metadata classes are not meant to be instantiated.
private TableAMetadata()
{
}

public int aID { get; set; }

[Association("TableA_TableB", "aID", "bID"), Include()]
public EntityCollection<TableB> TableBs { get; set; }

public string aName { get; set; }
}
}
C# Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[MetadataTypeAttribute(typeof(TableA.TableAMetadata))]
public partial class TableA
{
    internal sealed class TableAMetadata
    {

        // Metadata classes are not meant to be instantiated.
        private TableAMetadata()
        {
        }

        public int aID { get; set; }

        [Association("TableA_TableB", "aID", "bID"), Include()]
        public EntityCollection<TableB> TableBs { get; set; }

        public string aName { get; set; }
    }
}


Zuletzt bearbeitet von FrEEzE2046 am 10:16:43 01.09.2010, insgesamt 1-mal bearbeitet
FrEEzE2046
Mitglied

Benutzerprofil
Anmeldungsdatum: 03.12.2008
Beiträge: 786
Beitrag FrEEzE2046 Mitglied 10:23:37 01.09.2010   Titel:              Zitieren

Ich denke ich habe den Fehler gefunden. Meine Definition war einfach Quatsch:
Dies wäre die korrekte Association:

Association("TableA_TableB", "aID", "aID").

Die Referenz ist meiner eigenen Klasse ist natürlich aID. Der Fremdschlüssel jedoch ebenfalls ;-)

Rein theoretisch scheint nun alles korrekt zu sein, jedoch bekomme ich folgende Fehlermeldung:

Code:
Association named 'TableA_TableB' defined on entity type 'MyApplication.Web.Models.TableA' is invalid: OtherKey property named 'aID' cannot be found on entity type 'MyApplication.Web.Models.TableB'.
Code:
Association named 'TableA_TableB' defined on entity type 'MyApplication.Web.Models.TableA' is invalid: OtherKey property named 'aID' cannot be found on entity type 'MyApplication.Web.Models.TableB'.
Code:
Association named 'TableA_TableB' defined on entity type 'MyApplication.Web.Models.TableA' is invalid: OtherKey property named 'aID' cannot be found on entity type 'MyApplication.Web.Models.TableB'.


Die Aussage der Fehlermeldung ist natürlich korrekt, jedoch frage ich mich warum er überhaupt in TableB danach sucht und nicht in der Cross Table?!
witte
Mitglied

Benutzerprofil
Anmeldungsdatum: 08.01.2008
Beiträge: 1295
Beitrag witte Mitglied 12:59:06 01.09.2010   Titel:              Zitieren

Im Entity Data Model gibt es ein Spezialfall der hier zutrifft. Zwischen den Entities gibt es Relationsobjekte die über die Entity Keys die Beziehungen der Objekte zueinander beschreiben. Normalerweise wäre es so:
Code:
TableA <-RelationAAB-> TableAB <-RelationABB-> TableB
Code:
TableA <-RelationAAB-> TableAB <-RelationABB-> TableB
Code:
TableA <-RelationAAB-> TableAB <-RelationABB-> TableB

Also wie die Tabellen und Fremdschlüsselbeziehungen in der DB sind. Nun gibt es aber den Sonderfall. Wenn TableAB
* die beiden Fremdschlüssel als ihren Primärschlüssel definiert
* kein weiteres Attribut sich in der Tabelle befindet
kann das Entity TableAB entfallen weil die dazwischenliegende Relation mächtig genug ist diese Beziehung auszudrücken
Code:
TableA <-RelationAB-> TableB
Code:
TableA <-RelationAB-> TableB
Code:
TableA <-RelationAB-> TableB

Exakt aus diesem Grund kannst du von TableA nach TableB navigieren. Würdest du nur ein Attribut in TableAB hinzufügen und das Modell neu generieren würde es ganz anders laufen.
Möglicherweise solltest du deshalb gleich eine Assoziation nach TableB bauen aber ich kenne mich mit diesen Service-Objekten nicht aus.
FrEEzE2046
Mitglied

Benutzerprofil
Anmeldungsdatum: 03.12.2008
Beiträge: 786
Beitrag FrEEzE2046 Mitglied 21:40:09 01.09.2010   Titel:              Zitieren

Danke für deine Antwort.
Ich sehe schon, es gibt keinen anderen Weg als ein Dummy-Feld einzuführen. Die habe ich nun getan und kann meine join table nun auch im Model sehen.
Nun schaffe ich es jedoch nicht die Association korrekt zu definieren.

Sieht nun also so aus:

SQL-Datenbank:
TableA
Code:
    - aID int identity(1,1) not null
    - aName varchar(32) identity(1,1) not null
Code:
- aID int identity(1,1) not null
- aName varchar(32) identity(1,1) not null
Code:
    - aID int identity(1,1) not null
    - aName varchar(32) identity(1,1) not null


TableB
Code:
    - bID int not null
    - bName varchar(32) not null
Code:
- bID int not null
- bName varchar(32) not null
Code:
    - bID int not null
    - bName varchar(32) not null


TableA_B
Code:
    - aID int
    - bID int
    - Dummy bit
Code:
- aID int
- bID int
- Dummy bit
Code:
    - aID int
    - bID int
    - Dummy bit


DomainService Meta-Klassen:
TableA
C# Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
    [MetadataTypeAttribute(typeof(TableA.TableAMetadata))]
    public partial class TableA
    {
        internal sealed class TableAMetadata
        {

            // Metadata classes are not meant to be instantiated.
            private TableAMetadata()
            {
            }

            [Include(), Association("TableA", "aID", "aID")]
            public EntityCollection<Group_Module> Group_Module { get; set; }

            public int aID { get; set; }

            public string aName { get; set; }
        }
    }
C# Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[MetadataTypeAttribute(typeof(TableA.TableAMetadata))]
public partial class TableA
{
internal sealed class TableAMetadata
{

// Metadata classes are not meant to be instantiated.
private TableAMetadata()
{
}

[Include(), Association("TableA", "aID", "aID")]
public EntityCollection<Group_Module> Group_Module { get; set; }

public int aID { get; set; }

public string aName { get; set; }
}
}
C# Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
    [MetadataTypeAttribute(typeof(TableA.TableAMetadata))]
    public partial class TableA
    {
        internal sealed class TableAMetadata
        {

            // Metadata classes are not meant to be instantiated.
            private TableAMetadata()
            {
            }

            [Include(), Association("TableA", "aID", "aID")]
            public EntityCollection<Group_Module> Group_Module { get; set; }

            public int aID { get; set; }

            public string aName { get; set; }
        }
    }


TableB
C# Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
    [MetadataTypeAttribute(typeof(TableA_B.TableA_BMetadata))]
    public partial class TableA_B
    {
        internal sealed class TableA_BMetadata
        {

            // Metadata classes are not meant to be instantiated.
            private TableA_BMetadata()
            {
            }

            public TableA TableA { get; set; }

            public int aID { get; set; }

            public Nullable<bool> Dummy { get; set; }

            [Include(), Association("FK_TableA_B_TableB", "bID", "bID")]
            public TableB TableB { get; set; }

            public int bID { get; set; }
        }
    }
C# Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
[MetadataTypeAttribute(typeof(TableA_B.TableA_BMetadata))]
public partial class TableA_B
{
internal sealed class TableA_BMetadata
{

// Metadata classes are not meant to be instantiated.
private TableA_BMetadata()
{
}

public TableA TableA { get; set; }

public int aID { get; set; }

public Nullable<bool> Dummy { get; set; }

[Include(), Association("FK_TableA_B_TableB", "bID", "bID")]
public TableB TableB { get; set; }

public int bID { get; set; }
}
}
C# Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
    [MetadataTypeAttribute(typeof(TableA_B.TableA_BMetadata))]
    public partial class TableA_B
    {
        internal sealed class TableA_BMetadata
        {

            // Metadata classes are not meant to be instantiated.
            private TableA_BMetadata()
            {
            }

            public TableA TableA { get; set; }

            public int aID { get; set; }

            public Nullable<bool> Dummy { get; set; }

            [Include(), Association("FK_TableA_B_TableB", "bID", "bID")]
            public TableB TableB { get; set; }

            public int bID { get; set; }
        }
    }


Die Query im DomainService sieht nun so aus:
C# Code:
        public IQueryable<TableA> GetTableAsWithAssociatedTableBs()
        {
            return this.ObjectContext.TableAs.Include("FK_TableA_B_TableB").Include("TableB").ToList().AsQueryable();
C# Code:
public IQueryable<TableA> GetTableAsWithAssociatedTableBs()
{
return this.ObjectContext.TableAs.Include("FK_TableA_B_TableB").Include("TableB").ToList().AsQueryable();
C# Code:
        public IQueryable<TableA> GetTableAsWithAssociatedTableBs()
        {
            return this.ObjectContext.TableAs.Include("FK_TableA_B_TableB").Include("TableB").ToList().AsQueryable();

}

Leider wird nichts inkludiert ...
witte
Mitglied

Benutzerprofil
Anmeldungsdatum: 08.01.2008
Beiträge: 1295
Beitrag witte Mitglied 12:30:15 03.09.2010   Titel:              Zitieren

FrEEzE2046 schrieb:
Die Query im DomainService sieht nun so aus:
C# Code:
        public IQueryable<TableA> GetTableAsWithAssociatedTableBs()
        {
            return this.ObjectContext.TableAs.Include("FK_TableA_B_TableB").Include("TableB").ToList().AsQueryable();
C# Code:
public IQueryable<TableA> GetTableAsWithAssociatedTableBs()
{
return this.ObjectContext.TableAs.Include("FK_TableA_B_TableB").Include("TableB").ToList().AsQueryable();
C# Code:
        public IQueryable<TableA> GetTableAsWithAssociatedTableBs()
        {
            return this.ObjectContext.TableAs.Include("FK_TableA_B_TableB").Include("TableB").ToList().AsQueryable();

}

Leider wird nichts inkludiert ...
Das Chaining funktioniert so nicht. Das wird jetzt so verstanden dass TableA zwei NavProperties hat, eine zu FK_TableA_B_TableB und eine zu TableB. Du meinst wahrscheinlich
C# Code:
this.ObjectContext.TableAs.Include("FK_TableA_B_TableB.TableB")
C# Code:
this.ObjectContext.TableAs.Include("FK_TableA_B_TableB.TableB")
C# Code:
this.ObjectContext.TableAs.Include("FK_TableA_B_TableB.TableB")
wenn FK_TableA_B_TableB tatsächlich ein NavProperty ist.
C/C++ Forum :: C# und .NET ::  DataGrid als Row für DataGrid   Auf Beitrag antworten

Zeige alle Beiträge auf einer Seite




Nächstes Thema anzeigen
Vorheriges Thema anzeigen
Sie können Beiträge in dieses Forum schreiben.
Sie können auf Beiträge in diesem Forum antworten.
Sie können Ihre Beiträge in diesem Forum nicht bearbeiten.
Sie können Ihre Beiträge in diesem Forum nicht löschen.
Sie können an Umfragen in diesem Forum nicht mitmachen.

Powered by phpBB © 2001, 2002 phpBB Group :: FI Theme

c++.de ist Teilnehmer des Partnerprogramms von Amazon Europe S.à.r.l. und Partner des Werbeprogramms, das zur Bereitstellung eines Mediums für Websites konzipiert wurde, mittels dessen durch die Platzierung von Werbeanzeigen und Links zu amazon.de Werbekostenerstattung verdient werden kann.

Die Vervielfältigung der auf den Seiten www.c-plusplus.de, www.c-plusplus.info, www.c-sar.de, www.c-plusplus.net und www.baeckmann.de enthaltenen Informationen ohne eine schriftliche Genehmigung des Seitenbetreibers ist untersagt (vgl. §4 Urheberrechtsgesetz). Die Nutzung und Änderung der vorgestellten Strukturen und Verfahren in privaten und kommerziellen Softwareanwendungen ist ausdrücklich erlaubt, soweit keine Rechte Dritter verletzt werden. Der Seitenbetreiber übernimmt keine Gewähr für die Funktion einzelner Beiträge oder Programmfragmente, insbesondere übernimmt er keine Haftung für eventuelle aus dem Gebrauch entstehenden Folgeschäden.