This project is read-only.

Readonly property that has no backing attribute

Mar 8, 2012 at 12:42 PM

I have a Read Only property (only has a getter) to combine another two properties to display First and Last names as Full name.
The problem that I am running into is when I run the linq statement without doing the ToList() first it tries to convert and use the Read Only property 
in the query and fails. Is there a way to make this work?



public class User{
  public string Firstname {get;set;}
  public string Lastname {get;set;}
  public string Fullname {
    get { return string.format("{0} {1}", Firstname, Lastname); }


FAIL -- Server.Query<User>().Where(user => user.Firstname == "test").Select(user => new {Name = user.Fullname });
Success -- Server.Query<User>().Where(user => user.Firstname == "test").ToList().Select(user => new {Name = user.Fullname }); 

Mar 12, 2012 at 8:10 PM

The select projection builds the list of attributes to select.  Since FullName is not a mapped property it doesn't know how to turn that into an attribute to be requested from the directory.  You would have to build that value in the projection:

Server.Query<User>().Where(user => user.Firstname == "test").Select(user => new {Name = string.format("{0} {1}", user.Firstname, user.Lastname) });