Skip to content
This repository was archived by the owner on Mar 9, 2025. It is now read-only.
/ examples Public archive

Commit 2d6f237

Browse files
committed
Added Linq over WCF example.
1 parent 6fa0aa8 commit 2d6f237

File tree

83 files changed

+10298
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+10298
-2
lines changed

LinqOverWCF/ASP.NET Host/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ Web Application
1010
Client
1111
------
1212

13-
1413
1. Install an apporopriate linq2db nuget.
15-
2. Open [LinqToDB.Templates\CopyMe.XXXX.tt.txt](https://github.com/linq2db/examples/blob/master/SqlServer/GetStarted/LinqToDB.Templates/CopyMe.SqlServer.tt.txt) and follow the instructions inside the file.
14+
2. Open [LinqToDB.Templates\CopyMe.XXXX.tt.txt](https://github.com/linq2db/examples/blob/master/LinqOverWCF/ASP.NET Host/Client/LinqToDB.Templates/CopyMe.SqlServer.tt.txt) and follow the instructions inside the file.
1615
3. Modify your DataModel.tt file in the likeness of [Northwind.tt](https://github.com/linq2db/examples/blob/master/LinqOverWCF/ASP.NET Host/Client/Northwind.tt).
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
5+
</startup>
6+
</configuration>
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{87BCCF94-E214-46E4-A00B-ED2174587A14}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>Client</RootNamespace>
11+
<AssemblyName>Client</AssemblyName>
12+
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<PlatformTarget>AnyCPU</PlatformTarget>
18+
<DebugSymbols>true</DebugSymbols>
19+
<DebugType>full</DebugType>
20+
<Optimize>false</Optimize>
21+
<OutputPath>bin\Debug\</OutputPath>
22+
<DefineConstants>DEBUG;TRACE</DefineConstants>
23+
<ErrorReport>prompt</ErrorReport>
24+
<WarningLevel>4</WarningLevel>
25+
</PropertyGroup>
26+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27+
<PlatformTarget>AnyCPU</PlatformTarget>
28+
<DebugType>pdbonly</DebugType>
29+
<Optimize>true</Optimize>
30+
<OutputPath>bin\Release\</OutputPath>
31+
<DefineConstants>TRACE</DefineConstants>
32+
<ErrorReport>prompt</ErrorReport>
33+
<WarningLevel>4</WarningLevel>
34+
</PropertyGroup>
35+
<ItemGroup>
36+
<Reference Include="linq2db, Version=1.0.7.3, Culture=neutral, PublicKeyToken=f19f8aed7feff67e, processorArchitecture=MSIL">
37+
<HintPath>..\packages\linq2db.1.0.7.3\lib\net45\linq2db.dll</HintPath>
38+
<Private>True</Private>
39+
</Reference>
40+
<Reference Include="System" />
41+
<Reference Include="System.Core" />
42+
<Reference Include="System.Runtime.Serialization" />
43+
<Reference Include="System.ServiceModel" />
44+
<Reference Include="System.Xml.Linq" />
45+
<Reference Include="System.Data.DataSetExtensions" />
46+
<Reference Include="Microsoft.CSharp" />
47+
<Reference Include="System.Data" />
48+
<Reference Include="System.Net.Http" />
49+
<Reference Include="System.Xml" />
50+
</ItemGroup>
51+
<ItemGroup>
52+
<Compile Include="Northwind.generated.cs">
53+
<AutoGen>True</AutoGen>
54+
<DesignTime>True</DesignTime>
55+
<DependentUpon>Northwind.tt</DependentUpon>
56+
</Compile>
57+
<Compile Include="Program.cs" />
58+
<Compile Include="Properties\AssemblyInfo.cs" />
59+
</ItemGroup>
60+
<ItemGroup>
61+
<None Include="App.config" />
62+
<None Include="LinqToDB.Templates\DataAnnotations.ttinclude" />
63+
<None Include="LinqToDB.Templates\DataModel.ttinclude" />
64+
<None Include="LinqToDB.Templates\EditableObject.ttinclude" />
65+
<None Include="LinqToDB.Templates\LinqToDB.Access.ttinclude" />
66+
<None Include="LinqToDB.Templates\LinqToDB.DB2.ttinclude" />
67+
<None Include="LinqToDB.Templates\LinqToDB.Firebird.ttinclude" />
68+
<None Include="LinqToDB.Templates\LinqToDB.Informix.ttinclude" />
69+
<None Include="LinqToDB.Templates\LinqToDB.MySql.ttinclude" />
70+
<None Include="LinqToDB.Templates\LinqToDB.Oracle.ttinclude" />
71+
<None Include="LinqToDB.Templates\LinqToDB.PostgreSQL.ttinclude" />
72+
<None Include="LinqToDB.Templates\LinqToDB.SqlCe.ttinclude" />
73+
<None Include="LinqToDB.Templates\LinqToDB.SQLite.ttinclude" />
74+
<None Include="LinqToDB.Templates\LinqToDB.SqlServer.SqlTypes.Tools.ttinclude" />
75+
<None Include="LinqToDB.Templates\LinqToDB.SqlServer.SqlTypes.ttinclude" />
76+
<None Include="LinqToDB.Templates\LinqToDB.SqlServer.Tools.ttinclude" />
77+
<None Include="LinqToDB.Templates\LinqToDB.SqlServer.ttinclude" />
78+
<None Include="LinqToDB.Templates\LinqToDB.Sybase.ttinclude" />
79+
<None Include="LinqToDB.Templates\LinqToDB.Tools.ttinclude" />
80+
<None Include="LinqToDB.Templates\LinqToDB.ttinclude" />
81+
<None Include="LinqToDB.Templates\NotifyPropertyChanged.ttinclude" />
82+
<None Include="LinqToDB.Templates\PluralizationService.ttinclude" />
83+
<None Include="LinqToDB.Templates\ReadMe.LinqToDB.md" />
84+
<None Include="LinqToDB.Templates\T4Model.ttinclude" />
85+
<None Include="LinqToDB.Templates\Validation.ttinclude" />
86+
<None Include="packages.config" />
87+
</ItemGroup>
88+
<ItemGroup>
89+
<Content Include="LinqToDB.Templates\CopyMe.SqlServer.tt.txt" />
90+
<Content Include="Northwind.tt">
91+
<Generator>TextTemplatingFileGenerator</Generator>
92+
<LastGenOutput>Northwind.generated.cs</LastGenOutput>
93+
</Content>
94+
</ItemGroup>
95+
<ItemGroup>
96+
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
97+
</ItemGroup>
98+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
99+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
100+
Other similar extension points exist, see Microsoft.Common.targets.
101+
<Target Name="BeforeBuild">
102+
</Target>
103+
<Target Name="AfterBuild">
104+
</Target>
105+
-->
106+
</Project>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<#@ template language="C#" debug="True" hostSpecific="True" #>
2+
<#@ output extension=".generated.cs" #>
3+
<#@ include file="$(ProjectDir)LinqToDB.Templates\LinqToDB.SqlServer.Tools.ttinclude" #>
4+
<#@ include file="$(ProjectDir)LinqToDB.Templates\PluralizationService.ttinclude" #>
5+
<#
6+
/*
7+
1. Copy this file to a folder where you would like to generate your data model,
8+
rename it, and delete .txt extension. For example:
9+
10+
MyProject
11+
DataModels
12+
MyDatabase.tt
13+
14+
2. Modify the connection settings below to connect to your database.
15+
16+
3. Add connection string to the web/app.config file:
17+
18+
<connectionStrings>
19+
<add name="MyDatabase" providerName="System.Data.SqlClient"
20+
connectionString="Data Source=.;Database=MyDatabase;User Id=User;Password=TestPassword;" />
21+
</connectionStrings>
22+
23+
4. To access your database use the following code:
24+
25+
using (var db = new MyDatabaseDB())
26+
{
27+
var q =
28+
from c in db.Customers
29+
select c;
30+
31+
foreach (var c in q)
32+
Console.WriteLine(c.ContactName);
33+
}
34+
35+
5. See more at https://github.com/linq2db/t4models/blob/master/Templates/ReadMe.LinqToDB.md.
36+
37+
If you need to use the Microsoft.SqlServer.Types namespace, install the Microsoft.SqlServer.Types nuget,
38+
and replace the following include at the top of this file:
39+
40+
"$(ProjectDir)LinqToDB.Templates\LinqToDB.SqlServer.Tools.ttinclude"
41+
42+
with
43+
44+
"$(ProjectDir)LinqToDB.Templates\LinqToDB.SqlServer.SqlTypes.Tools.ttinclude"
45+
*/
46+
47+
NamespaceName = "DataModels";
48+
49+
LoadSqlServerMetadata("MyServer", "MyDatabase", "User", "Password");
50+
// LoadSqlServerMetadata(".", "MyDatabase"); // Integrated Security
51+
// LoadSqlServerMetadata(string connectionString);
52+
53+
GenerateModel();
54+
#>
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<#
2+
{
3+
var beforeGenerateModel = BeforeGenerateModel;
4+
BeforeGenerateModel = () =>
5+
{
6+
beforeGenerateModel();
7+
DataAnnotationsImpl();
8+
};
9+
}
10+
#>
11+
<#+
12+
void DataAnnotationsImpl()
13+
{
14+
foreach (Class cl in GetTreeNodes(Model).OfType<Class>())
15+
{
16+
foreach (var p in GetTreeNodes(cl).OfType<Property>())
17+
{
18+
if (p.DisplayName != null)
19+
{
20+
p.Attributes.Add(new Attribute("Display", "Name=\"" + p.DisplayName + "\"") { IsSeparated = true });
21+
}
22+
23+
if (p.IsRequired)
24+
{
25+
var attr = new Attribute("Required") { IsSeparated = true };
26+
27+
if (p.IsRequiredMessage != null)
28+
attr.Parameters.Add(string.Format("ErrorMessage=\"" + p.IsRequiredMessage + "\"", p.DisplayName ?? p.Name));
29+
30+
p.Attributes.Add(attr);
31+
}
32+
33+
if (p.StringLength > 0)
34+
{
35+
var attr = new Attribute("StringLength", p.StringLength.ToString()) { IsSeparated = true };
36+
37+
if (p.StringLengthMessage != null)
38+
attr.Parameters.Add(string.Format("ErrorMessage=\"" + p.StringLengthMessage + "\"", p.DisplayName ?? p.Name));
39+
40+
p.Attributes.Add(attr);
41+
42+
// p.Attributes.Add(
43+
// new Attribute("StringLength",
44+
// p.StringLength.ToString(),
45+
// string.Format(
46+
// "ErrorMessage=\"The {0} must be a string with a maximum lenfth of {1}.\"",
47+
// p.DisplayName ?? "field",
48+
// p.StringLength))
49+
// {
50+
// IsSeparated = true
51+
// });
52+
}
53+
}
54+
}
55+
}
56+
57+
partial class Property
58+
{
59+
public string DisplayName;
60+
public bool IsRequired;
61+
public string IsRequiredMessage;
62+
public int StringLength;
63+
public string StringLengthMessage;
64+
}
65+
#>

0 commit comments

Comments
 (0)