使用foreach从表中获取每个值. [英] take each values from a table using a foreach ..

查看:167
本文介绍了使用foreach从表中获取每个值.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我在项目中使用实体框架.
现在正在使用


I am using an entity frame work in my project.
now am using

var list = from s in _db.Lists select s;



用于从表中获取所有值.
我怎样才能从表中只获得两列?
之后,我必须使用foreach循环从表中获取每个值.我该怎么办呢?
在此先感谢



this for taking all the values from the table.
how can i get only two columns from a table.?
after that i have to take each value from the table using a foreach loop.How can i do this???
Thanks in advance

推荐答案

要只获取一些列,您需要创建一个投影

To get only some columns you need to create a projection

var list = from s in db.Lists
           select s.column1, s.column2


这篇关于使用foreach从表中获取每个值.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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