本文整理汇总了C#中DataContext.GetCommand方法的典型用法代码示例。如果您正苦于以下问题:C# DataContext.GetCommand方法的具体用法?C# DataContext.GetCommand怎么用?C# DataContext.GetCommand使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataContext
的用法示例。
在下文中一共展示了DataContext.GetCommand方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateDataContext
public void CreateDataContext()
{
string connectionString = "DbLinqProvider=Sqlite;" +
"DbLinqConnectionType=Mono.Data.Sqlite.SqliteConnection, Mono.Data.Sqlite;" +
"Data Source=Northwind.db3";
var dc = new DataContext(connectionString);
Assert.AreEqual(typeof(SqliteConnection), dc.Connection.GetType());
var dcq = from p in dc.GetTable<Product>() where p.ProductName == "Chai" select p.ProductID;
var cmd = dc.GetCommand(dcq);
var dcc = dcq.ToList().Count;
Assert.AreEqual(dcc, 1);
}
示例2: WriteLog
/// <summary>
/// 用于Linq写Log
/// </summary>
/// <param name="dc"></param>
/// <param name="query"></param>
/// <param name="IsWriteSql"></param>
public static void WriteLog(DataContext dc, IQueryable query, bool IsWriteSql)
{
if (IsWriteSql)
{
DbCommand cmd = dc.GetCommand(query);
WriteLog(cmd.CommandText);
}
}
示例3: GetFullQueryInfo
private SqlQueryText[] GetFullQueryInfo(DataContext dataContext, IQueryable query)
{
System.Data.Common.DbCommand dbCommand = dataContext.GetCommand(query);
SqlQueryText[] result = new SqlQueryText[1];
for (int i = 0, n = 1; i < n; i++) {
result[i].Text = dbCommand.CommandText;
int nParams = dbCommand.Parameters.Count ;
result[i].Params = new ParameterText[nParams];
for (int j = 0; j < nParams; j++) {
ParameterText param = new ParameterText();
System.Data.Common.DbParameter pInfo = dbCommand.Parameters[j];
param.Name = pInfo.ParameterName;
param.SqlType = pInfo.DbType.ToString();
Console.WriteLine("Before SqlType= " + param.SqlType);
object paramValue = pInfo.Value;
if (paramValue == null) {
param.Value = null;
} else {
param.Value = pInfo.Value.ToString();
}
result[i].Params[j] = param;
}
}
return result;
}