如何动态创建LINQ QUERY?
有什么办法可以动态地在 { } 之间插入部分代码吗?
LINQ QUERY:
var csvdata = from csvline in csvlines
let column = csvline.Split(';')
select new {
produkt = column[0],
cislo = column[1],
part = column[2],
serial = column[3]
};
我的意思是:
string qpart = "produkt = column[0], cislo = column[1], part = column[2], serial = column[3]";
var csvdata = from csvline in csvlines
let column = csvline.Split(';')
select new {
qpart
};
谢谢您的回答..
Is there any way to insert part of the code between { } dynamically?
LINQ QUERY:
var csvdata = from csvline in csvlines
let column = csvline.Split(';')
select new {
produkt = column[0],
cislo = column[1],
part = column[2],
serial = column[3]
};
I mean something like:
string qpart = "produkt = column[0], cislo = column[1], part = column[2], serial = column[3]";
var csvdata = from csvline in csvlines
let column = csvline.Split(';')
select new {
qpart
};
Thanks for answers..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试研究动态 Linq 查询库。
http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx
http://naspinski.net/post/Writing-Dynamic -Linq-Queries-in-Linq-to-Entities.aspx
您需要将从 Split 返回的字符串数组转换为 IQueryable 才能工作,但我认为这是您最好的选择。
我想象它会如何工作?
Try investigating Dynamic Linq Query Library.
http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx
http://naspinski.net/post/Writing-Dynamic-Linq-Queries-in-Linq-to-Entities.aspx
You'll need to convert the string array returned from Split into IQueryable for it to work but I think this is your best shot.
Is how I'd I imagine it would work?.