我已经能够使用linq从表中获取值。
var q=(from app in context.Applicant
where app.ApplicantName=="")
现在我想要的是:
var q=(from app in context.Applicant
where app.stringIhave =="") // so instead of column name I have string which has same name as column.
是否可以在“选择”中指定字符串,因为这不确定我在每种情况下会得到什么,所以我一直需要不同的数据。
有可能这样做吗?如果否,那么我会找出其他的东西。更新我有一个GlobalString,它保存一个表的列名称。因此,当我查询该表时,我仅从字符串中指定要获取的列值:
var q=(from app in context.Applicants
where app.ID==1013
select GlobalString //which is specifying that I want to get value from which column, as column name is not fixed.
//where GlobalString can have values like: app.FirstName..app.LastName etc
更新1:
var q = context.Applicants.Select("new(it.ApplicantFirstName as FirstName, it.ApplicantLastName as LastName)");
错误信息:
The query syntax is not valid. Near keyword 'AS'
您可以为此使用Dynamic Linq(可从NuGet获得):
var q = context.Applicant.Where(app.stringIhave + " = @0", "");
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句