开发者

LINQ to SQL (Executing Custom SQL Expressions) : how to substitute a parameter with an array value

Usage of method:

DataContext.ExecuteQuery<TResult>(String, Object[]);

The following generates an InvalidOperationException with message:

{"Could not format node 'Value' for execution as SQL."}

int[] ids = new int[] {1, 2, 3};
context.ExecuteQuery<SourceTarget>(select c.* from Customer c where c.customer_id in {0}, ids);

Your help wi开发者_Go百科ll be really appreciated.


Since you're using LINQ-to-SQL, you could use the LINQ syntax instead of ExecuteQuery, eg:

var customers = from c in context.Customers
                where ids.Contains(c.customer_id)
                select c;

Or, if you insist on making it a SQL query, try:

context.ExecuteQuery<SourceTarget>(String.Format("select c.* from Customer c where c.customer_id in ({0})",
    String.Join(",", ids)));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜