Skip to content

Commit 8c8cbf9

Browse files
Youssef1313mairaw
andauthored
Fix code snippets (#3089)
* Fix code snippets * Apply suggestions from code review Co-Authored-By: Maira Wenzel <[email protected]> * Apply missing fix * Apply missing fix * Apply missing fix * Apply missing fix * Apply suggestions from code review Co-Authored-By: Maira Wenzel <[email protected]> * Apply missing fix * minor fix * Apply missing fix * Update DataContext.xml * Apply suggestions from code review Co-Authored-By: Maira Wenzel <[email protected]> Co-authored-by: Maira Wenzel <[email protected]>
1 parent 96bf121 commit 8c8cbf9

File tree

12 files changed

+325
-305
lines changed

12 files changed

+325
-305
lines changed

xml/System.Data.Linq/DataContext.xml

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -580,21 +580,28 @@
580580
581581
`ExecuteQuery` and `ExecuteCommand` allow you to specify a variable number of arguments for parameter substitution. For example, you can specify the parameters when invoking ExecuteQuery\<TResult>:
582582
583-
```
584-
db.ExecuteQuery<Customer>("select * from dbo.Customers where City = {0}", "London");
585-
```
583+
```csharp
584+
db.ExecuteQuery<Customer>("SELECT * FROM dbo.Customers WHERE City = {0}", "London");
585+
```
586+
587+
```vb
588+
db.ExecuteQuery(Of Customer)("SELECT * FROM dbo.Customers WHERE City = {0}", "London")
589+
```
586590
587591
And, another example:
588592
589-
```
590-
db.ExecuteCommand("UPDATE Products SET QuantityPerUnit = {0} WHERE ProductID = {1}", "24 boxes", 5);
591-
```
592-
593-
The following example opens a connection and passes a SQL `UPDATE` command to the SQL engine.
594-
595-
596-
597-
## Examples
593+
```csharp
594+
db.ExecuteCommand("UPDATE Products SET QuantityPerUnit = {0} WHERE ProductID = {1}", "24 boxes", 5);
595+
```
596+
597+
```vb
598+
db.ExecuteCommand("UPDATE Products SET QuantityPerUnit = {0} WHERE ProductID = {1}", "24 boxes", 5)
599+
```
600+
601+
602+
## Examples
603+
The following example opens a connection and passes a SQL `UPDATE` command to the SQL engine.
604+
598605
[!code-csharp[DLinqCommunicatingWithDatabase#3](~/samples/snippets/csharp/VS_Snippets_Data/DLinqCommunicatingWithDatabase/cs/Program.cs#3)]
599606
[!code-vb[DLinqCommunicatingWithDatabase#3](~/samples/snippets/visualbasic/VS_Snippets_Data/DLinqCommunicatingWithDatabase/vb/Module1.vb#3)]
600607
@@ -883,29 +890,30 @@ db.ExecuteCommand("UPDATE Products SET QuantityPerUnit = {0} WHERE ProductID = {
883890
884891
- In all other cases, the query can retrieve just a subset of the tracked fields and properties for the object.
885892
886-
The following C# snippet shows one use for this method:
893+
## Examples
894+
895+
The following example shows one use for this method:
887896
888-
```
889-
var customers = db.ExecuteQuery<Customer>(@"SELECT CustomerID, CompanyName, ContactName, ContactTitle,
897+
```csharp
898+
var customers = db.ExecuteQuery<Customer>(@"SELECT CustomerID, CompanyName, ContactName, ContactTitle,
890899
Address, City, Region, PostalCode, Country, Phone, Fax
891-
FROM   dbo.Customers
892-
WHERE  City = {0}", "London");
900+
FROM   dbo.Customers
901+
WHERE  City = {0}", "London");
893902
894-
foreach (Customer c in customers)
895-
Console.WriteLine(c.ContactName);
903+
foreach (Customer c in customers)
904+
Console.WriteLine(c.ContactName);
896905
```
897906
898-
In Visual Basic
899-
900-
```
901-
Dim customers = db.ExecuteQuery(Of Customer)("SELECT CustomerID, _ CompanyName, ContactName, ContactTitle, _
902-
Address, City, Region, PostalCode, Country, Phone, Fax _
903-
FROM dbo.Customers _
904-
WHERE City = {0}", "London")
905-
906-
For Each c As Customer In customers
907-
Console.WriteLine(c.ContactName)
908-
Next
907+
```vb
908+
Dim customers = db.ExecuteQuery(Of Customer)("SELECT CustomerID, _
909+
CompanyName, ContactName, ContactTitle, _
910+
Address, City, Region, PostalCode, Country, Phone, Fax _
911+
FROM dbo.Customers _
912+
WHERE City = {0}", "London")
913+
914+
For Each c As Customer In customers
915+
Console.WriteLine(c.ContactName)
916+
Next
909917
```
910918
911919
]]></format>
@@ -1508,7 +1516,7 @@ Next
15081516
## Remarks
15091517
Each row in the <xref:System.Data.IDataReader> is converted to an object in the <xref:System.Collections.Generic.IEnumerable%601>.
15101518
1511-
```
1519+
```csharp
15121520
public IEnumerable<T> Translate<T>(IDataReader reader) {}
15131521
```
15141522

xml/System.Data.Linq/EntitySet`1.xml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -284,26 +284,26 @@
284284
<remarks>
285285
<format type="text/markdown"><![CDATA[
286286
287-
## Remarks
288-
The following C# sample shows one use of this method:
287+
## Examples
288+
289+
The following example shows one use of this method:
289290
290-
```
291+
```csharp
291292
var customer = (from c in db.Customers
292293
where c.CustomerID == "ALFKI"
293-
select c).Single();
294-
295-
Order[] orderArray = new Order[customer.Orders.Count];
294+
select c).Single();
295+
296+
var orderArray = new Order[customer.Orders.Count];
297+
customer.Orders.CopyTo(orderArray,0);
296298
```
297299
298-
customer.Orders.CopyTo(orderArray,0);In Visual Basic:
299-
300-
```
300+
```vb
301301
Dim customer = (From c In db.Customers _
302302
Where c.CustomerID = "ALFKI" _
303303
Select c).[Single]()
304304
305-
Dim orderArray As Order() = New Order(customer.Orders.Count - 1) {}
306-
customer.Orders.CopyTo(orderArray, 0)
305+
Dim orderArray As New Order(customer.Orders.Count - 1) {}
306+
customer.Orders.CopyTo(orderArray, 0)
307307
```
308308
309309
]]></format>

xml/System.Data.Linq/Table`1.xml

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,19 @@
5757
5858
An application can access a <xref:System.Data.Linq.Table%601> instance via <xref:System.Data.Linq.DataContext.GetTable%2A> or by using a strongly typed property for the strongly typed <xref:System.Data.Linq.DataContext>. That is, when the designer generates a DataContext object, it generates properties to represent each Table. For example:
5959
60-
```
60+
```csharp
6161
[global::System.Data.Linq.Mapping.DatabaseAttribute(Name="SignOffTool")]
62-
public partial class DataClasses1DataContext : System.Data.Linq.DataContext {
63-
public System.Data.Linq.Table<User> Users {
64-
get {
65-
return this.GetTable<User>();
66-
}
67-
}
68-
}
69-
```
62+
public partial class DataClasses1DataContext : System.Data.Linq.DataContext
63+
{
64+
public System.Data.Linq.Table<User> Users
65+
{
66+
get
67+
{
68+
return this.GetTable<User>();
69+
}
70+
}
71+
}
72+
```
7073
7174
For this strongly typed DataContext, you can access the Users property to get `Table<User>`.
7275
@@ -91,16 +94,17 @@ public partial class DataClasses1DataContext : System.Data.Linq.DataContext {
9194
9295
When a new entity is attached, deferred loaders for any child collections (for example, `EntitySet` collections of entities from associated tables) are initialized. When <xref:System.Data.Linq.DataContext.SubmitChanges%2A> is called, members of the child collections are put into an `Unmodified` state. To update members of a child collection, you must explicitly call `Attach` and specify that entity.
9396
94-
`Attach` attaches all entities in the object graph of the provided object. For example, the following C# code:
97+
`Attach` attaches all entities in the object graph of the provided object. For example:
9598
96-
```
97-
using (SampleDataContext db = new SampleDataContext()) {
98-
Employee employee = new Employee { employeeId = 1 };
99+
```csharp
100+
using (var db = new SampleDataContext())
101+
{
102+
var employee = new Employee { employeeId = 1 };
99103
100-
Master master = new Master();
104+
var master = new Master();
101105
master.Employee = employee;
102106
103-
Child child = new Child();
107+
var child = new Child();
104108
child.Employee = employee;
105109
106110
db.Employees.Attach(employee);
@@ -110,14 +114,12 @@ using (SampleDataContext db = new SampleDataContext()) {
110114
db.Masters.InsertOnSubmit(master);
111115
112116
db.SubmitChanges();
113-
}
114-
117+
}
115118
```
116-
117-
The equivalent Visual Basic code is:
118-
119-
```
120-
Using db As New SampleDataContext() Dim employee As New Employee With { .employeeId = 1 }
119+
120+
```vb
121+
Using db As New SampleDataContext()
122+
Dim employee As New Employee With { .employeeId = 1 }
121123
122124
Dim master As New Master()
123125
master.Employee = employee
@@ -449,20 +451,20 @@ End Using
449451
## Remarks
450452
Entities that are put into the pending delete state with this method do not disappear from query results until after <xref:System.Data.Linq.DataContext.SubmitChanges%2A> is called. Disconnected entities must be attached before they can be deleted. For more information, see [Data Retrieval and CUD Operations in N-Tier Applications (LINQ to SQL)](~/docs/framework/data/adonet/sql/linq/data-retrieval-and-cud-operations-in-n-tier-applications.md).
451453
452-
The following C# snippet shows one use for this method:
454+
## Examples
455+
456+
The following example shows one use for this method:
453457
454-
```
458+
```csharp
455459
IEnumerable<Customer> customersWithoutOrders = (from c in db.Customers
456460
where c.Orders.Count == 0
457461
select c).ToList();
458-
462+
459463
db.Customers.DeleteAllOnSubmit(customersWithoutOrders);
460464
db.SubmitChanges();
461465
```
462466
463-
In Visual Basic:
464-
465-
```
467+
```vb
466468
Dim customersWithoutOrders As IEnumerable(Of Customer) = (From c In db.Customers _
467469
Where c.Orders.Count = 0 _
468470
Select c).ToList()

0 commit comments

Comments
 (0)