Search code examples
c#-4.0wcf-ria-services

Implement interface member 'System.Collections.IEnumerable.GetEnumerator()'


In the Demo WCF, I am having an error when try to creat class inherits IList<>

public class Profileview: IList<Profile>
{
    public Profile ViewProfile(int accountID)
    {
        return this.Where(p => p.AccountId == accountID).First();
    }
}

this is service

namespace DemoService
{
    [ServiceContract]
    public interface IProfileService
    {
        [OperationContract]
        Profile ViewProfile(int accountID);
    }

    [DataContract]
    public class Profile
    {
        [DataMember]
        public string FirstName { get; set; }

        [DataMember]
        public string LastName { get; set; }

        [DataMember]
        public string Location { get; set; }

        [DataMember]
        public string Genre { get; set; }

        [DataMember]
        public int AccountId { get; set; }
    }
}

Error 1 'ICService.Profileview' does not implement interface member 'System.Collections.IEnumerable.GetEnumerator()'

Can you tell me how to fix it. Thanks :)


Solution

  • You are not inheriting from IList<Profile> because it is an interface. You are implementing this interface and as such you need to implement all methods required by that interface - which are quite a lot.

    I think you really want to inherit from List<Profile>.