LINQ to DataSet Dataclass assignment question

Posted by Overhed on Stack Overflow See other posts from Stack Overflow or by Overhed
Published on 2010-02-02T23:17:08Z Indexed on 2010/03/31 2:23 UTC
Read the original article Hit count: 556

Hi all,

I'm working on a Silverlight project trying to access a database using LINQ To DataSet and then sending data over to Silverlight via .ASMX web service.

I've defined my DataSet using the Server Explorer tool (dragging and dropping all the different tables that I'm interested in). The DataSet is able to access the server and database with no issues.

Below is code from one of my Web Methods:

    public  List<ClassSpecification> getSpecifications()
    {
        DataSet2TableAdapters.SpecificationTableAdapter Sta = new DataSet2TableAdapters.SpecificationTableAdapter();

        return (from Spec in Sta.GetData().AsEnumerable()
                select new ClassSpecification()
                {
                    Specification = Spec.Field<String>("Specification"),
                    SpecificationType = Spec.Field<string>("SpecificationType"),
                    StatusChange = Spec.Field<DateTime>("StatusChange"),
                    Spec = Spec.Field<int>("Spec")
                }).ToList<ClassSpecification>();
    }

I created a "ClassSpecification" data class which is going to contain my data and it has all the table fields as properties.

My question is, is there a quicker way of doing the assignment than what is shown here? There are actually about 10 more fields, and I would imagine that since my DataSet knows my table definition, that I would have a quicker way of doing the assignment than going field by field. I tried just "select new ClassSpecification()).ToList

Any help would be greatly appreciated.

© Stack Overflow or respective owner

Related posts about Silverlight

Related posts about linq-to-dataset