Print Page | Close Window

Projection into Known Type

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3836
Printed Date: 13-May-2026 at 1:02am


Topic: Projection into Known Type
Posted By: gregweb
Subject: Projection into Known Type
Date Posted: 05-Dec-2012 at 10:52am
I created a test query against NorthwindIB. If I run the query without using a known type, then it returns the expected data. But when I add the EmployeeSlice, then it returns the correct number of entities, but there is no data in the entities. I am currently using version 6.1.5. The EmployeeSlice is defined on the Server project, and linked to the SL project.



var query = em.Employees.Select(emp => new EmployeeSlice()
            {
               EmployeeID = emp.EmployeeID,
               FirstName = emp.FirstName,
               LastName = emp.LastName
            }
               ).ExecuteAsync((results) =>
               {
                    foreach (var employee in results.Results)
                    {
                        //Return returns 9 slices, but all data is empty.
                    }
               });

[DataContract]
    public class EmployeeSlice : IKnownType
    {
        public int EmployeeID { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
    }



Replies:
Posted By: kimj
Date Posted: 05-Dec-2012 at 11:07am
Hi Greg,
 
Sinc you've added a DataContract attribute to the EmployeeSlice you also need to decorate members with the DataMember attribute.  Alternately, you can remove the DataContract attribute on the class, and all public properties will then serialize.


Posted By: gregweb
Date Posted: 06-Dec-2012 at 11:06am
Great, thanks.



Print Page | Close Window