日期:2014-05-17  浏览次数:20476 次

EF 查询 排除部分字段

用EF查询一个表,有个几个字段不需要查询。  因为表的字段比较多,一个个写需要的字段比较麻烦,能不能用什么排除法写不需要的字段?

------解决方案--------------------
查询,自己定义匿名对象.
如 ; var obj=from i in table 
            select new { 属性1=i.xx,属性2=i.xx};

自己选择需要的字段
------解决方案--------------------
var numbers = new int[] { 1, 2, 3, 4, 5, 6 };
numbers.Select(n => new { Number = n, IsEven = n % 2 == 0 })
------解决方案--------------------
试试这个帖子最后说的Ignore方法:http://stackoverflow.com/questions/1707663/exclude-a-field-property-from-the-database-with-entity-framework-4-code-first