LINQ to SQL
This topic applies to Windows Workflow Foundation 4 (WF4).
This sample demonstrates how to create an activity to use LINQ to SQL query entities from tables in SQL Server databases.
Note: |
---|
The WCF samples may already be installed on your machine. Check for the following (default) directory before continuing.
<InstallDrive>:\Samples\WCFWFCardspace
If this directory does not exist, click the download sample link at the top of this page. Note that this link downloads and installs all of the WF, WCF, and CardSpace samples. This sample is located in the following directory.
<InstallDrive>:\Samples\WCFWFCardSpace\WF\Scenario\ActivityLibrary\Linq\LinqToSql
|
Activity details for FindInSqlTable
This activity allows users to query entities from tables in a database using LINQ to SQL. Users of the activity can also provide a LINQ predicate in the form of a lambda expression to filter the results. If no predicate is provided, the entire table is returned. The following table details the property and return values for the activity.
Property or Return Value | Description |
---|---|
|
A required property that specifies the source collection. |
|
A required property that specifies the filter for the collection in the form of a lambda expression. |
Return Value |
The filtered collection. |
Code Sample that uses the Custom Activity
The following code example uses the FindInSqlTable
custom activity to find all rows in a SQL Server table named Employee
where the Role
column is equal to SDE
.
new FindInSqlTable<Employee>
{
ConnectionString = @"Data Source=.\SQLExpress;Initial Catalog=LinqToSqlSample;Integrated Security=True",
Predicate = new LambdaValue<Func<Employee, bool>>(c => new Func<Employee, bool>(emp => emp.Role.Equals("SDE"))),
Result = new OutArgument<IList<Employee>>(employees)
},
To use this sample
Open a command prompt.
Navigate to the folder that contains this sample.
Run the Setup.cmd command file.
Note
The Setup.cmd script attempts to install the sample database in your local machine SQL Server Express. If you want to install it in other SQL server instance, edit Setup.cmd.
The Setup.cmd script does the following actions.:
Creates a database called LinqToSqlSample.
Creates a Roles table.
Creates an Employees table.
Inserts 3 records into the Roles table.
Inserts 12 records into the Employees table.
Using Visual Studio 2010, open the LinqToSQL.sln solution file.
To build the solution, press CTRL+SHIFT+B.
To run the solution, press F5.
To uninstall the LinqToSql sample database
Open a command prompt.
Navigate to the folder that contains this sample.
Run the Cleanup.cmd command file.
Note: |
---|
The samples may already be installed on your machine. Check for the following (default) directory before continuing.
<InstallDrive>:\WF_WCF_Samples
If this directory does not exist, go to Windows Communication Foundation (WCF) and Windows Workflow Foundation (WF) Samples for .NET Framework 4 to download all Windows Communication Foundation (WCF) and WF samples. This sample is located in the following directory.
<InstallDrive>:\WF_WCF_Samples\WF\Scenario\ActivityLibrary\Liiinq\LinqToSql
|