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

解决方案 »

  1.   

    查询,自己定义匿名对象.
    如 ; var obj=from i in table 
                select new { 属性1=i.xx,属性2=i.xx};自己选择需要的字段
      

  2.   

    var numbers = new int[] { 1, 2, 3, 4, 5, 6 };
    numbers.Select(n => new { Number = n, IsEven = n % 2 == 0 })
      

  3.   

    试试这个帖子最后说的Ignore方法:http://stackoverflow.com/questions/1707663/exclude-a-field-property-from-the-database-with-entity-framework-4-code-first
      

  4.   


    我的意思就是一个个写 属性1=i.xx, 字段有点多了,有没有方便的方法,把不需要的那1、2个字段排除
      

  5.   


    谢谢大哥看得云里雾里的找了个国内的帖子,还是看不太懂。
    http://www.cnblogs.com/Gyoung/archive/2013/01/17/2864150.html