RIA services how do I return a single column?
I have a autocompletebox that is used to select a destination for a car booking program. For the itemssource of the autocomplete box I am trying to set it to all the previous destinations ent开发者_运维知识库ered. The problem is that I can't work out how to return a single column 'Destination' of distinct destination values from my Booking class, e.g.
var query = from bk in ObjectContext.Bookings select new DestinationDTO { Destination = bk.Destination };
return query.Distinct();
. I have tried creating a shared DestinationDTO class to return just the single column but can't work out how to get this to inherit from Entity!!
Any ideas?
You need to have a property with a [Key] attribute in your DestinationDTO class. Then RIA services will be able to generate a corresponding class on the client side.
public class DestinationDTO
{
[Key]
public Guid Id { get; set; }
public string Destination { get; set; }
}
Then just do this:
var query = from bk in ObjectContext.Bookings
select new DestinationDTO { Destination = bk.Destination, Id = Guid.NewGuid() };
return query.Distinct();
精彩评论