Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to Pass LINQ object form Biz Class
Message
De
06/07/2010 13:08:14
 
 
À
06/07/2010 12:40:04
James Blackburn
Qualty Design Systems, Inc.
Kuna, Idaho, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
LINQ
Divers
Thread ID:
01471528
Message ID:
01471547
Vues:
38
The results in the debug window are the same. You can view them in the Debugger but, as before, you will not be able to access them in code - except as dynamic types as mentioned in my other post. If you need to access the collection outside the getDirectory() method then use a known class. e.g:
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;
>        }
>
>
>>>Hi All
>>>I have the class below that I want to use to data from my EF setup. I can't figure out what type to make the method so I can return the resulting LINQ object. The code below gives me this error.
>>>
>>>Cannot implicitly convert type 'System.Collections.Generic.IEnumerable AnonymousType#1 to 'System.Linq.Enumerable'
>>>
>>>Thanks.
>>>
>>>
>>>    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.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform