0

Hi,
may i know how to write the method in web service if i want to get a description from a particular id ?

public List<EventEntity> GetDetails(string uid)
        {
            EventDBModelDataContext ct = new EventDBModelDataContext();
            var detail = ct.EventEntities.Where(d => d.eventID==uid).Select(d => new { d.eventID, d.eventDesc });
                        
            return detail.ToList();

        }

Still having the error message: Cannot implicitly convert type 'System.Collections.Generic.List<AnonymousType#1>' to 'System.Collections.Generic.List<WcfEstateService2.EventEntity>' I:\vs\WcfEstateService2\WcfEstateService2\ServiceImpl.svc.cs

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by thines01
0

If you are planning to return the eventID and the eventDesc as an EventEntity, you will need to new them as an EventEntity.

Something like (JUST GUESSING):

public List<EventEntity> GetDetails(string uid)
{
   EventDBModelDataContext ct = new EventDBModelDataContext();

   List<EventEntity> detail = ct.EventEntities.Where(d => d.eventID.Equals(uid))
      .Select(d => new EventEntity(){ eventID=d.eventID, eventDesc=d.eventDesc })
      .ToList();
                        
   return detail;
}

...otherwise, you're getting back an anonymous type and those can't be "return"ed

Edited by thines01: clarity

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.