New Posts New Posts RSS Feed: Selecting certain properties of a DF/EF object.
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Selecting certain properties of a DF/EF object.

 Post Reply Post Reply
Author
geo View Drop Down
Newbie
Newbie


Joined: 19-Oct-2010
Location: US
Posts: 1
Post Options Post Options   Quote geo Quote  Post ReplyReply Direct Link To This Post Topic: Selecting certain properties of a DF/EF object.
    Posted: 19-Oct-2010 at 5:56pm
How can I select certain properties to return without creating a new anonymous object? My goal is to use the Employee object I would normally get back but only fill certain properties in an effort to reduce the data going across my WCF service. Is this possible? With this code I get this error where I set Employee=item within my foreach loop.

Cannot implicitly convert type 'AnonymousType#1' to 'AmberStream.Model.Payroll.Employee'

            var query = _entityManager
                .Employees
                .AddIncludePaths("Person")
                .Where(col => col.Employee_ID == id)
                .Select(e => new { e.Employee_ID, e.Person.FirstName, e.Person.LastName })
                .ExecuteAsync(op => {
                    if (op.HasError)
                        throw op.Error;

                    foreach (var item in op.Results)
                    {
                        Employee = item; 
                    }
                    
                    // debugging log
                    ObjectDumper.Write(Employee);
                    ObjectDumper.Write(Employee.Person.FirstName);
                    ObjectDumper.Write(Employee.Person.LastName);
                });
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 20-Oct-2010 at 10:18am
geo,
 
you can try:
  .
  .
  .
  .Select(e => new { id = e.Employee_ID, fname = e.Person.FirstName, lname = e.Person.LastName })
  .
  .
  .
  foreach (var item in op.Results){
    Employee.Employee_ID = item.id;
    Employee.Person.FirstName = item.fname;
    Employee.Person.LastName = item.lname;
  }
 
 
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down