2011-11-14 91 views
2

我有一个为Linq to Sql编写的通用函数。(Linq to Entity)中(Linq to Sql)的GetCommand()函数的等效

一些代码是:

string sqlCmd = dc.GetCommand(q).CommandText; 
{ 
    foreach (System.Data.Common.DbParameter dbp in dc.GetCommand(q).Parameters) 
    { 
     cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter(dbp.ParameterName, dbp.Value)); 
    } 
} 

其中dc是一个DataContext。我正在使用ObjectContext。 q是System.Linq.IQueryable。所以尽管dc.GetCommand(q).CommandText。我应该使用什么知道。并且类似地对于DbParameter。任何帮助表示赞赏。

回答

1

EF不具有相当于GetCommand。如果您想要访问参数,请尝试使用EF Provider Wrapper(检查跟踪样本)。