# CSharpSample
**Repository Path**: maxwell/csharpsample
## Basic Information
- **Project Name**: CSharpSample
- **Description**: C# 示例代码
- **Primary Language**: C#
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 14
- **Forks**: 6
- **Created**: 2013-06-07
- **Last Updated**: 2022-12-01
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
Sample Queries
Welcome to the C# Samples
Unblocking Folder Links
If you have downloaded these samples from the Internet and the folder links
below do not function, you may need to unblock this ReadMe file. Try the
following steps:
- In Windows Explorer, right-click the
ReadMe.html file you loaded to view this page, and click
Properties.
- Click the Unblock button at the bottom of the property
pane, and then click OK.
Language Samples
We have created a set of language samples to help you get familiar with
various C# language features. They are available in the
LanguageSamples folder.
LINQ Samples
We have created four sets of samples for you that are designed to help you
learn LINQ quickly, and to act as a reference and guide for those with more
advanced skills. A few handy utilities are also included.
Important: If the folder links
below do not function, please follow the instructions above under
Unblocking Folder Links.
Getting Started with LINQ
- SampleQueries: This is the most important sample and
contains about 500 examples of how to use each of the query operators in LINQ
to Objects, LINQ to SQL, LINQ to XML and LINQ to DataSet.
- SimpleLinqToObjects:
The hello world of the LINQ samples.
This shows you how easy it is to do simple queries of in-memory objects using LINQ to
Objects.
- LinqToNorthwind: A basic example of how to use LINQ To SQL
to query a database.
- SimpleLinqToXml: Get started using LINQ to XML.
- WinFormsDataBinding: Learn how to display LINQ queries
with grids in a Windows form. It includes a one to many query example.
- XQuery: Another simple LINQ to XML sample query. This
sample shows the minimal code necessary to write a LINQ to XML query
- LinqToXmlDataBinding: Bind LINQ to XML code to WPF
controls.
Advanced Samples
- DynamicQuery: Code to create LINQ queries at run time.
- Reflector: Use LINQ to right queries against the
objects in your code using the Reflection APIs.
- RSS: This sample acts as a tiny web server that
aggregates several RSS feeds
- SimpleLambdas: Several examples of how to write
and use lambda expressions.
-
WebServiceLinqProvider: A sample showing how to create a LINQ
provider to query Terraserver, a web service offering geographical data.
Addins and Visualizers
- ExpressionTreeVisualizer: Create a visualization of an
Expression Tree.
- QueryVisualizer: Allows LINQ to SQL developers to see the
SQL for their query, and also to see the results of the query in a grid.
- PasteXmlAsLinq: A Visual Studio addin
that automatically converts XML markup to LINQ to XML code.
Note: Addins cannot be compiled or loaded within C#
Express.
Libraries or Utilities
- Data: Contains XML files and a modified copy
of the Northwind database for use by several of the other samples.
- ObjectDumper: A utility for writing the output from a LINQ
query to the screen in text mode.
- NorthwindMapping: Contains the ORM mapping created by the
LINQ to SQL designer for the Northwind database that ships with these samples.
It is used by DynamicQuery and WinFormsDataBinding.
- Whitepapers: The following papers are stored in this
directory in Word format:
- LINQ Project Overview
- LINQ to SQL Overview for C# and VB
- Standard Query Operators
- LINQ to XML Overview
LINQ Samples Database Connectivity Issues
The default connect string for the samples should work without modification
if you have SQL Server Express installed on your development machine. Here is an
alternate connect string that you can modify for your own purposes if you are
not using SQL Express but have SQL Server available. You will probably need to
modify the word test wherever it appears in the sample connect string.
string connString =
"server=test;database=northwind;user id=test;password=test";
On some SQL Express installations, you may not have the rights to start a
user instance. If you get an error message to that effect, try removing the
clause ";user instance = true" from the connection string.
Be sure that the copies of the northwind database that you are accessing are
not marked read only. If necessary, browse to the copy of NORTHWIND.MDF you are
trying to access, right click on the file, choose properties. Clear the
Read-only attribute.
On some slow machines, or when using a virtual pc, users have reported that
some database applications give errors the first time they run. Try running the
sample two or three times.
The customized copies of the Northwind database included with the samples
ship without an LDF (log) file. This is done intentionally, so that the LDF and
MDF files do not get out of sync. When you run a sample that uses the database,
or attach to the database from the Server Explorer inside Visual Studio, the LDF
file will be created automatically. You may have trouble connecting to the MDF
file if you are using the SQL Server Management Studio without first creating a
log file.