C#LINQ to SQL使用参数进行列名选择 [英] C# LINQ to SQL use parameter for columnname to select

查看:63
本文介绍了C#LINQ to SQL使用参数进行列名选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C#你好!当我将列名称作为字符串参数时,我需要编写LINQ查询,例如

private

C#  Hello! I need to write a LINQ query when I get the columnname as a string paramater, like

private

void paintRequest( string colName)
{
var qry = 来自 rec in dataContext
其中 rec。 (colName)!= null
选择 new {rec.field1,rec.field2,rec。(colName) }
}我试图实现它的每一种方式 - 失败...
你知道一种方法吗,或者它可能无法用LINQ实现?

void paintRequest(string colName)
{
  var qry = from rec in dataContext
where rec.(colName) != null
select new { rec.field1, rec.field2, rec.(colName) }
}
Every way I tried to implement it - failed...
Do you know a way to do it, or maybe it cannot be implemented using LINQ?

推荐答案

你好了

动态查询库就是这样做的:
http://weblogs.asp.net/scottgu/archive/2008/01/07/ dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx

Joe
Hi there

The dynamic query library does exactly this:
http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx

Joe


这篇关于C#LINQ to SQL使用参数进行列名选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆