Skip to content

Commit eae89cd

Browse files
Copilotadegeo
andcommitted
Migrate DataGrid SQL EF snippets to new location and fix VB type mismatch
Co-authored-by: adegeo <67293991+adegeo@users.noreply.github.com>
1 parent 3c6c1a2 commit eae89cd

17 files changed

+2343
-4
lines changed

dotnet-desktop-guide/wpf/controls/snippets/walkthrough-display-data-from-a-sql-server-database-in-a-datagrid-control/framework/csharp/AdventureWorksModel.Designer.cs

Lines changed: 871 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<edmx:Edmx Version="2.0" xmlns:edmx="http://schemas.microsoft.com/ado/2008/10/edmx">
3+
<!-- EF Runtime content -->
4+
<edmx:Runtime>
5+
<!-- SSDL content -->
6+
<edmx:StorageModels>
7+
<Schema Namespace="AdventureWorksLT2008Model.Store" Alias="Self" Provider="System.Data.SqlClient" ProviderManifestToken="2008" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2009/02/edm/ssdl">
8+
<EntityContainer Name="AdventureWorksLT2008ModelStoreContainer">
9+
<EntitySet Name="Product" EntityType="AdventureWorksLT2008Model.Store.Product" store:Type="Tables" Schema="SalesLT" />
10+
<EntitySet Name="ProductCategory" EntityType="AdventureWorksLT2008Model.Store.ProductCategory" store:Type="Tables" Schema="SalesLT" />
11+
<AssociationSet Name="FK_Product_ProductCategory_ProductCategoryID" Association="AdventureWorksLT2008Model.Store.FK_Product_ProductCategory_ProductCategoryID">
12+
<End Role="ProductCategory" EntitySet="ProductCategory" />
13+
<End Role="Product" EntitySet="Product" />
14+
</AssociationSet>
15+
<AssociationSet Name="FK_ProductCategory_ProductCategory_ParentProductCategoryID_ProductCategoryID" Association="AdventureWorksLT2008Model.Store.FK_ProductCategory_ProductCategory_ParentProductCategoryID_ProductCategoryID">
16+
<End Role="ProductCategory" EntitySet="ProductCategory" />
17+
<End Role="ProductCategory1" EntitySet="ProductCategory" />
18+
</AssociationSet>
19+
</EntityContainer>
20+
<EntityType Name="Product">
21+
<Key>
22+
<PropertyRef Name="ProductID" />
23+
</Key>
24+
<Property Name="ProductID" Type="int" Nullable="false" StoreGeneratedPattern="Identity" />
25+
<Property Name="Name" Type="nvarchar" Nullable="false" MaxLength="50" />
26+
<Property Name="ProductNumber" Type="nvarchar" Nullable="false" MaxLength="25" />
27+
<Property Name="Color" Type="nvarchar" MaxLength="15" />
28+
<Property Name="StandardCost" Type="money" Nullable="false" />
29+
<Property Name="ListPrice" Type="money" Nullable="false" />
30+
<Property Name="Size" Type="nvarchar" MaxLength="5" />
31+
<Property Name="Weight" Type="decimal" Precision="8" Scale="2" />
32+
<Property Name="ProductCategoryID" Type="int" />
33+
<Property Name="ProductModelID" Type="int" />
34+
<Property Name="SellStartDate" Type="datetime" Nullable="false" />
35+
<Property Name="SellEndDate" Type="datetime" />
36+
<Property Name="DiscontinuedDate" Type="datetime" />
37+
<Property Name="ThumbNailPhoto" Type="varbinary(max)" />
38+
<Property Name="ThumbnailPhotoFileName" Type="nvarchar" MaxLength="50" />
39+
<Property Name="rowguid" Type="uniqueidentifier" Nullable="false" />
40+
<Property Name="ModifiedDate" Type="datetime" Nullable="false" />
41+
</EntityType>
42+
<EntityType Name="ProductCategory">
43+
<Key>
44+
<PropertyRef Name="ProductCategoryID" />
45+
</Key>
46+
<Property Name="ProductCategoryID" Type="int" Nullable="false" StoreGeneratedPattern="Identity" />
47+
<Property Name="ParentProductCategoryID" Type="int" />
48+
<Property Name="Name" Type="nvarchar" Nullable="false" MaxLength="50" />
49+
<Property Name="rowguid" Type="uniqueidentifier" Nullable="false" />
50+
<Property Name="ModifiedDate" Type="datetime" Nullable="false" />
51+
</EntityType>
52+
<Association Name="FK_Product_ProductCategory_ProductCategoryID">
53+
<End Role="ProductCategory" Type="AdventureWorksLT2008Model.Store.ProductCategory" Multiplicity="0..1" />
54+
<End Role="Product" Type="AdventureWorksLT2008Model.Store.Product" Multiplicity="*" />
55+
<ReferentialConstraint>
56+
<Principal Role="ProductCategory">
57+
<PropertyRef Name="ProductCategoryID" />
58+
</Principal>
59+
<Dependent Role="Product">
60+
<PropertyRef Name="ProductCategoryID" />
61+
</Dependent>
62+
</ReferentialConstraint>
63+
</Association>
64+
<Association Name="FK_ProductCategory_ProductCategory_ParentProductCategoryID_ProductCategoryID">
65+
<End Role="ProductCategory" Type="AdventureWorksLT2008Model.Store.ProductCategory" Multiplicity="0..1" />
66+
<End Role="ProductCategory1" Type="AdventureWorksLT2008Model.Store.ProductCategory" Multiplicity="*" />
67+
<ReferentialConstraint>
68+
<Principal Role="ProductCategory">
69+
<PropertyRef Name="ProductCategoryID" />
70+
</Principal>
71+
<Dependent Role="ProductCategory1">
72+
<PropertyRef Name="ParentProductCategoryID" />
73+
</Dependent>
74+
</ReferentialConstraint>
75+
</Association>
76+
</Schema>
77+
</edmx:StorageModels>
78+
<!-- CSDL content -->
79+
<edmx:ConceptualModels>
80+
<Schema Namespace="AdventureWorksLT2008Model" Alias="Self" xmlns:annotation="http://schemas.microsoft.com/ado/2009/02/edm/annotation" xmlns="http://schemas.microsoft.com/ado/2008/09/edm">
81+
<EntityContainer Name="AdventureWorksLT2008Entities" annotation:LazyLoadingEnabled="true">
82+
<EntitySet Name="Products" EntityType="AdventureWorksLT2008Model.Product" />
83+
<EntitySet Name="ProductCategories" EntityType="AdventureWorksLT2008Model.ProductCategory" />
84+
<AssociationSet Name="FK_Product_ProductCategory_ProductCategoryID" Association="AdventureWorksLT2008Model.FK_Product_ProductCategory_ProductCategoryID">
85+
<End Role="ProductCategory" EntitySet="ProductCategories" />
86+
<End Role="Product" EntitySet="Products" />
87+
</AssociationSet>
88+
<AssociationSet Name="FK_ProductCategory_ProductCategory_ParentProductCategoryID_ProductCategoryID" Association="AdventureWorksLT2008Model.FK_ProductCategory_ProductCategory_ParentProductCategoryID_ProductCategoryID">
89+
<End Role="ProductCategory" EntitySet="ProductCategories" />
90+
<End Role="ProductCategory1" EntitySet="ProductCategories" />
91+
</AssociationSet>
92+
</EntityContainer>
93+
<EntityType Name="Product">
94+
<Key>
95+
<PropertyRef Name="ProductID" />
96+
</Key>
97+
<Property Name="ProductID" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
98+
<Property Name="Name" Type="String" Nullable="false" MaxLength="50" Unicode="true" FixedLength="false" />
99+
<Property Name="ProductNumber" Type="String" Nullable="false" MaxLength="25" Unicode="true" FixedLength="false" />
100+
<Property Name="Color" Type="String" MaxLength="15" Unicode="true" FixedLength="false" />
101+
<Property Name="StandardCost" Type="Decimal" Nullable="false" Precision="19" Scale="4" />
102+
<Property Name="ListPrice" Type="Decimal" Nullable="false" Precision="19" Scale="4" />
103+
<Property Name="Size" Type="String" MaxLength="5" Unicode="true" FixedLength="false" />
104+
<Property Name="Weight" Type="Decimal" Precision="8" Scale="2" />
105+
<Property Name="ProductCategoryID" Type="Int32" />
106+
<Property Name="ProductModelID" Type="Int32" />
107+
<Property Name="SellStartDate" Type="DateTime" Nullable="false" />
108+
<Property Name="SellEndDate" Type="DateTime" />
109+
<Property Name="DiscontinuedDate" Type="DateTime" />
110+
<Property Name="ThumbNailPhoto" Type="Binary" MaxLength="Max" FixedLength="false" />
111+
<Property Name="ThumbnailPhotoFileName" Type="String" MaxLength="50" Unicode="true" FixedLength="false" />
112+
<Property Name="rowguid" Type="Guid" Nullable="false" />
113+
<Property Name="ModifiedDate" Type="DateTime" Nullable="false" />
114+
<NavigationProperty Name="ProductCategory" Relationship="AdventureWorksLT2008Model.FK_Product_ProductCategory_ProductCategoryID" FromRole="Product" ToRole="ProductCategory" />
115+
</EntityType>
116+
<EntityType Name="ProductCategory">
117+
<Key>
118+
<PropertyRef Name="ProductCategoryID" />
119+
</Key>
120+
<Property Name="ProductCategoryID" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
121+
<Property Name="ParentProductCategoryID" Type="Int32" />
122+
<Property Name="Name" Type="String" Nullable="false" MaxLength="50" Unicode="true" FixedLength="false" />
123+
<Property Name="rowguid" Type="Guid" Nullable="false" />
124+
<Property Name="ModifiedDate" Type="DateTime" Nullable="false" />
125+
<NavigationProperty Name="Products" Relationship="AdventureWorksLT2008Model.FK_Product_ProductCategory_ProductCategoryID" FromRole="ProductCategory" ToRole="Product" />
126+
<NavigationProperty Name="ProductCategory1" Relationship="AdventureWorksLT2008Model.FK_ProductCategory_ProductCategory_ParentProductCategoryID_ProductCategoryID" FromRole="ProductCategory" ToRole="ProductCategory1" />
127+
<NavigationProperty Name="ProductCategory2" Relationship="AdventureWorksLT2008Model.FK_ProductCategory_ProductCategory_ParentProductCategoryID_ProductCategoryID" FromRole="ProductCategory1" ToRole="ProductCategory" />
128+
</EntityType>
129+
<Association Name="FK_Product_ProductCategory_ProductCategoryID">
130+
<End Role="ProductCategory" Type="AdventureWorksLT2008Model.ProductCategory" Multiplicity="0..1" />
131+
<End Role="Product" Type="AdventureWorksLT2008Model.Product" Multiplicity="*" />
132+
<ReferentialConstraint>
133+
<Principal Role="ProductCategory">
134+
<PropertyRef Name="ProductCategoryID" />
135+
</Principal>
136+
<Dependent Role="Product">
137+
<PropertyRef Name="ProductCategoryID" />
138+
</Dependent>
139+
</ReferentialConstraint>
140+
</Association>
141+
<Association Name="FK_ProductCategory_ProductCategory_ParentProductCategoryID_ProductCategoryID">
142+
<End Role="ProductCategory" Type="AdventureWorksLT2008Model.ProductCategory" Multiplicity="0..1" />
143+
<End Role="ProductCategory1" Type="AdventureWorksLT2008Model.ProductCategory" Multiplicity="*" />
144+
<ReferentialConstraint>
145+
<Principal Role="ProductCategory">
146+
<PropertyRef Name="ProductCategoryID" />
147+
</Principal>
148+
<Dependent Role="ProductCategory1">
149+
<PropertyRef Name="ParentProductCategoryID" />
150+
</Dependent>
151+
</ReferentialConstraint>
152+
</Association>
153+
</Schema>
154+
</edmx:ConceptualModels>
155+
<!-- C-S mapping content -->
156+
<edmx:Mappings>
157+
<Mapping Space="C-S" xmlns="http://schemas.microsoft.com/ado/2008/09/mapping/cs">
158+
<EntityContainerMapping StorageEntityContainer="AdventureWorksLT2008ModelStoreContainer" CdmEntityContainer="AdventureWorksLT2008Entities">
159+
<EntitySetMapping Name="Products"><EntityTypeMapping TypeName="AdventureWorksLT2008Model.Product"><MappingFragment StoreEntitySet="Product">
160+
<ScalarProperty Name="ProductID" ColumnName="ProductID" />
161+
<ScalarProperty Name="Name" ColumnName="Name" />
162+
<ScalarProperty Name="ProductNumber" ColumnName="ProductNumber" />
163+
<ScalarProperty Name="Color" ColumnName="Color" />
164+
<ScalarProperty Name="StandardCost" ColumnName="StandardCost" />
165+
<ScalarProperty Name="ListPrice" ColumnName="ListPrice" />
166+
<ScalarProperty Name="Size" ColumnName="Size" />
167+
<ScalarProperty Name="Weight" ColumnName="Weight" />
168+
<ScalarProperty Name="ProductCategoryID" ColumnName="ProductCategoryID" />
169+
<ScalarProperty Name="ProductModelID" ColumnName="ProductModelID" />
170+
<ScalarProperty Name="SellStartDate" ColumnName="SellStartDate" />
171+
<ScalarProperty Name="SellEndDate" ColumnName="SellEndDate" />
172+
<ScalarProperty Name="DiscontinuedDate" ColumnName="DiscontinuedDate" />
173+
<ScalarProperty Name="ThumbNailPhoto" ColumnName="ThumbNailPhoto" />
174+
<ScalarProperty Name="ThumbnailPhotoFileName" ColumnName="ThumbnailPhotoFileName" />
175+
<ScalarProperty Name="rowguid" ColumnName="rowguid" />
176+
<ScalarProperty Name="ModifiedDate" ColumnName="ModifiedDate" />
177+
</MappingFragment></EntityTypeMapping></EntitySetMapping>
178+
<EntitySetMapping Name="ProductCategories"><EntityTypeMapping TypeName="AdventureWorksLT2008Model.ProductCategory"><MappingFragment StoreEntitySet="ProductCategory">
179+
<ScalarProperty Name="ProductCategoryID" ColumnName="ProductCategoryID" />
180+
<ScalarProperty Name="ParentProductCategoryID" ColumnName="ParentProductCategoryID" />
181+
<ScalarProperty Name="Name" ColumnName="Name" />
182+
<ScalarProperty Name="rowguid" ColumnName="rowguid" />
183+
<ScalarProperty Name="ModifiedDate" ColumnName="ModifiedDate" />
184+
</MappingFragment></EntityTypeMapping></EntitySetMapping>
185+
</EntityContainerMapping>
186+
</Mapping>
187+
</edmx:Mappings>
188+
</edmx:Runtime>
189+
<!-- EF Designer content (DO NOT EDIT MANUALLY BELOW HERE) -->
190+
<Designer xmlns="http://schemas.microsoft.com/ado/2008/10/edmx">
191+
<Connection>
192+
<DesignerInfoPropertySet>
193+
<DesignerProperty Name="MetadataArtifactProcessing" Value="EmbedInOutputAssembly" />
194+
</DesignerInfoPropertySet>
195+
</Connection>
196+
<Options>
197+
<DesignerInfoPropertySet>
198+
<DesignerProperty Name="ValidateOnBuild" Value="true" />
199+
<DesignerProperty Name="EnablePluralization" Value="True" />
200+
<DesignerProperty Name="IncludeForeignKeysInModel" Value="True" />
201+
</DesignerInfoPropertySet>
202+
</Options>
203+
<!-- Diagram content (shape and connector positions) -->
204+
<Diagrams>
205+
<Diagram Name="AdventureWorksModel">
206+
<EntityTypeShape EntityType="AdventureWorksLT2008Model.Product" Width="1.5" PointX="3" PointY="1" Height="4.480205078125" IsExpanded="true" />
207+
<EntityTypeShape EntityType="AdventureWorksLT2008Model.ProductCategory" Width="1.5" PointX="0.75" PointY="2" Height="2.5571907552083326" IsExpanded="true" />
208+
<AssociationConnector Association="AdventureWorksLT2008Model.FK_Product_ProductCategory_ProductCategoryID" ManuallyRouted="false">
209+
<ConnectorPoint PointX="2.25" PointY="3.2785953776041663" />
210+
<ConnectorPoint PointX="3" PointY="3.2785953776041663" />
211+
</AssociationConnector>
212+
<AssociationConnector Association="AdventureWorksLT2008Model.FK_ProductCategory_ProductCategory_ParentProductCategoryID_ProductCategoryID" ManuallyRouted="false">
213+
<ConnectorPoint PointX="1.2819230769230767" PointY="4.5571907552083326" />
214+
<ConnectorPoint PointX="1.2819230769230767" PointY="4.8071907552083326" />
215+
<ConnectorPoint PointX="1.7284615384615383" PointY="4.8071907552083326" />
216+
<ConnectorPoint PointX="1.7284615384615383" PointY="4.5571907552083326" />
217+
</AssociationConnector>
218+
</Diagram>
219+
</Diagrams>
220+
</Designer>
221+
</edmx:Edmx>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<connectionStrings>
4+
<add name="AdventureWorksLT2008Entities" connectionString="metadata=res://*/AdventureWorksModel.csdl|res://*/AdventureWorksModel.ssdl|res://*/AdventureWorksModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=cuejimwalk01\sqlexpadv;Initial Catalog=AdventureWorksLT2008;Integrated Security=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />
5+
</connectionStrings>
6+
</configuration>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Application x:Class="DataGridSQLExample.App"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
StartupUri="MainWindow.xaml">
5+
<Application.Resources>
6+
7+
</Application.Resources>
8+
</Application>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Configuration;
4+
using System.Data;
5+
using System.Linq;
6+
using System.Windows;
7+
8+
namespace DataGridSQLExample
9+
{
10+
/// <summary>
11+
/// Interaction logic for App.xaml
12+
/// </summary>
13+
public partial class App : Application
14+
{
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>WinExe</OutputType>
5+
<TargetFramework>net48</TargetFramework>
6+
<UseWPF>true</UseWPF>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="EntityFramework" Version="6.4.4" />
11+
</ItemGroup>
12+
13+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!-- <MainWindowXaml> -->
2+
<Window x:Class="DataGridSQLExample.MainWindow"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
Title="MainWindow" Height="350" Width="450"
6+
Loaded="Window_Loaded">
7+
<Grid>
8+
<!-- <DataGridControl> -->
9+
<DataGrid Name="dataGrid1" />
10+
<!-- </DataGridControl> -->
11+
</Grid>
12+
</Window>
13+
<!-- </MainWindowXaml> -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// <LoadDataFromDatabase>
2+
using System.Data.Entity.Core.Objects;
3+
using System.Linq;
4+
using System.Windows;
5+
6+
namespace DataGridSQLExample
7+
{
8+
/// <summary>
9+
/// Interaction logic for MainWindow.xaml
10+
/// </summary>
11+
public partial class MainWindow : Window
12+
{
13+
AdventureWorksLT2008Entities dataEntities = new AdventureWorksLT2008Entities();
14+
15+
public MainWindow()
16+
{
17+
InitializeComponent();
18+
}
19+
20+
private void Window_Loaded(object sender, RoutedEventArgs e)
21+
{
22+
var query =
23+
from product in dataEntities.Products
24+
where product.Color == "Red"
25+
orderby product.ListPrice
26+
select new { product.Name, product.Color, CategoryName = product.ProductCategory.Name, product.ListPrice };
27+
28+
dataGrid1.ItemsSource = query.ToList();
29+
}
30+
}
31+
}
32+
// </LoadDataFromDatabase>

0 commit comments

Comments
 (0)