public class Address { public string Address1 { get; set; } //etc }then:
public IEnumerable<Address> getDirectory() { var queryobj = from dr in this.oEFobject.DIRECTORies select new Address { Address1 = dr.ADDRESS1 //etc }; return queryobj; }>I can make this work but the resulting object is different and I can't get to the table columns. I am sending two images form my watch list. queryvar is the link result object and dcvar is the var within a foreach loop.
> public IQueryable getDirectory() > { > IQueryable queryobj = null; > queryobj = from dr in this.oEFobject.DIRECTORies > select new > { > dr.ADDRESS1, > dr.ADDRESS2, > dr.CITY, > dr.COMPANYNAME > }; > > return queryobj; > } >>
>>> public class MyBizClass >>> { >>> private CornMazeYellowPagesEntities oEFobject = null; >>> public MyBizClass() >>> { >>> this.oEFobject = new CornMazeYellowPagesEntities(); >>> } >>> >>> public Enumerable getDirectory() >>> { >>> //CornMazeYellowPagesEntities queryobj = null; >>> var queryobj = from dr in this.oEFobject.DIRECTORies.AsEnumerable() >>> select new >>> { >>> dr.ADDRESS1, >>> dr.ADDRESS2, >>> dr.CITY, >>> dr.COMPANYNAME >>> }; >>> >>> //queryobj = >>> // from dr in this.oEFobject.DIRECTORies >>> // select dr; >>> >>> return queryobj; >>> } >>> } >>>The problem isn't with IEnumerable as such but because you are creating an anonymous type which, by definition, cannot be used outside of where it is created - i.e there's no way the object created by 'select new {}' can be used outside of the getDirectory() method. You could create a light-weight class to do the job - but define it somewhere where it can be accessible whereever it will be used.