[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 192
  • Last Modified:

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

0
NoSleepForTheWeary
Asked:
NoSleepForTheWeary
  • 3
  • 2
1 Solution
 
Fernando SotoCommented:
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
 
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 SotoCommented:
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 SotoCommented:
Not a problem, glad I was able to help.  ;=)
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now