new to linq and wcf contracts

I am hving trouble trying to figure out how to return a list type when I set up the select to return specific columns as opposed to the all the columns. Not sure if I should be returning a list or another type. this is what I have so far not sure of the exact syntax.
[OperationContract]
        public List<> GetCerts()
        {
            SALARYDCDataContext db = new SALARYDCDataContext();
            // var selected_rows = from row in db.TBLCERTs select row;
            //return selected_rows.ToList();
            var GC = from c in db.TBLCERTs
                     select new
                     { c.CERTID,
                       Certification = c.CERTCODE + " - " + c.CERTDESC
                      };
                    return GC.ToList();
        }

Open in new window

NoSleepForTheWearyAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fernando SotoRetiredCommented:
Hi NoSleepForTheWeary;

What I would do is to create a class like the GCData in the code snippet below and then when you create the new item in the select create it as a new GCData also in the code snippet. The class must be accessible from where ever you use it.

Fernando
[OperationContract]
public List<GCData> GetCerts()
{
    SALARYDCDataContext db = new SALARYDCDataContext();
    // var selected_rows = from row in db.TBLCERTs select row;
    //return selected_rows.ToList();
    var GC = from c in db.TBLCERTs
             select new GCData
             { 
                 CERTID = c.CERTID,
                 Certification = c.CERTCODE + " - " + c.CERTDESC
             };
            return GC.ToList();
}
 
 
 
public class GCData
{
    String CERTID { get; set; }
    String Certification { get; set; }
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NoSleepForTheWearyAuthor Commented:
I tried the code in the service.svc.cs file and it gave me 2 errors.
'SALARY.Web.GCData.CERTID' is inaccessible due to its protection level
'SALARY.Web.GCData.Certification' is inaccessible due to its protection level
not sure what to make of these.
0
Fernando SotoRetiredCommented:
Hi NoSleepForTheWeary;

The statement in my last post, "The class must be accessible from where ever you use it.", In your scenario it must be defined with in the web service project/class and it also needs to be defined in the client project/class.

Fernando
0
NoSleepForTheWearyAuthor Commented:
ok figured it out needed to make the int and string a public member of the class. thanks for the help
public class GCData
    {
        public int CERTID { get; set; }
        public String Certification { get; set; }
    } 

Open in new window

0
Fernando SotoRetiredCommented:
Not a problem, glad I was able to help.  ;=)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.