DataContext.Log 屬性

定義

取得或設定寫入 SQL 查詢或命令的目的。Gets or sets the destination to write the SQL query or command.

public:
 property System::IO::TextWriter ^ Log { System::IO::TextWriter ^ get(); void set(System::IO::TextWriter ^ value); };
public System.IO.TextWriter Log { get; set; }
member this.Log : System.IO.TextWriter with get, set
Public Property Log As TextWriter

屬性值

要用於寫入命令的 TextReaderThe TextReader to use for writing the command.

範例

下列範例會在顯示查詢結果之前,于主控台視窗中顯示產生的 SQL。The following example displays generated SQL in the console window before it displays the results of the query.

db.Log = Console.Out;
var custQuery =
    from cust in db.Customers
    where cust.City == "London"
    select cust;

foreach (var custObj in custQuery)
{
    Console.WriteLine(custObj.ContactName);
}
db.Log = Console.Out
Dim custQuery = _
From cust In db.Customers _
Where cust.City = "London" _
Select cust

For Each custObj In custQuery
    Console.WriteLine(custObj.ContactName)
Next

備註

將此屬性設定null為以停用命令記錄。Set this property to null to disable command logging.

適用於