Data Platform Developer Center > Data Platform Development Forums > WCF Data Services (formerly known as ADO.NET Data Services) > Error when tried to Add Service Referente to ADO.NET Data Service using POCO class at the server (DataServiceClientGenerator) from Visual Studio 2008
Ask a questionAsk a question
 

AnswerError when tried to Add Service Referente to ADO.NET Data Service using POCO class at the server (DataServiceClientGenerator) from Visual Studio 2008

  • Thursday, October 29, 2009 3:27 PMLagear Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    I've the next error when try to Add Service Reference to a ADO.NET Data Service

    Error 1 Custom tool error: Schema specified is not valid. Errors: 
    (0,0) : error 0005: The 'Relationship' attribute is invalid - The value '.User_Contacts' is invalid according to its datatype 'http://schemas.microsoft.com/ado/2006/04/edm:TQualifiedName' - The Pattern constraint failed.
    (0,0) : error 0005: The 'Association' attribute is invalid - The value '.User_Contacts' is invalid according to its datatype 'http://schemas.microsoft.com/ado/2006/04/edm:TQualifiedName' - The Pattern constraint failed. D:\Lagear\AstoriaConsola\Service References\ServiceReference1\Reference.datasvcmap 1 1 AstoriaConsola

    The source code for the service is:

    using System;
     using System.Collections.Generic;
     using System.Data.Services;
     using System.Linq;
     namespace CustomDataService
     {
        public class User
        {
            public int ID { get; set; }
            public string Name { get; set; }
            public IList<Contact> Contacts{get; set;}
        }
        public class Contact
        {
            public int ID { get; set; }
            public string Name { get; set; }
            public string Email { get; set; }
        }
        public class ContactsData : //IUpdatable
        {
            #region Populate Service Data
            static User[] _users;
            static Contact[] _contacts;
            static ContactsData()
            {
                _users = new User[]{
                  new User(){ ID=0, Name="Mike",Contacts= new List<Contact>()},
                  new User(){ ID=1, Name="Saaid",Contacts= new List<Contact>()},
                  new User(){ ID=2, Name="John",Contacts= new List<Contact>()},
                  new User(){ ID=3, Name="Pablo",Contacts= newList<Contact>()}};
                _contacts = new Contact[]{
                  new Contact(){ ID=0, Name="Mike", Email="mike@contoso.com" },
                  new Contact(){ ID=1, Name="Saaid", Email="Saaid@hotmail.com"},
                  new Contact(){ ID=2, Name="John", Email="j123@live.com"},
                  new Contact(){ ID=3, Name="Pablo", Email="Pablo@mail.com"}};
                _users[0].Contacts.Add(_contacts[0]);
                _users[0].Contacts.Add(_contacts[1]);
                _users[1].Contacts.Add(_contacts[2]);
                _users[1].Contacts.Add(_contacts[3]);
            }
            #endregion
            public IQueryable<User> Users
            {
                get { return _users.AsQueryable<User>(); }
            }
            public IQueryable<Contact> Contacts
            {
                get { throw new DataServiceException(403, "Requests directly to
                                                   /Contacts are not allowed");}
            }
        public class contacts : DataService<ContactsData>
        {
            // This method is called only once to initialize
            //service-wide policies.
            public static void InitializeService(IDataServiceConfiguration
                                                 config)
            {
                config.SetEntitySetAccessRule("*", EntitySetRights.All);
            }
           //Service operations, query interceptors & change interceptors go here
        }
     }
    There is some attribute to decorate Contacts property?

    Best,

    Marcos


    Someday i need to know about something

Answers

  • Thursday, October 29, 2009 3:47 PMVitek Karas - MSFT Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi,

    I tried the code above and it works just fine for me.

    But - just a wild guess - you don't really have a namespace around the classes right? Because when I remove the namespace (and fixup the .svc file) then I get the same error you do.

    This is a known problem with the ADO.NET Data Services. We don't really support correctly if the classes defining entities don't have any namespace. To fix this just add the namespace around the classes (as you do have above) and it should just work.

    Thanks,
    Vitek Karas [MSFT]

All Replies

  • Thursday, October 29, 2009 3:47 PMVitek Karas - MSFT Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi,

    I tried the code above and it works just fine for me.

    But - just a wild guess - you don't really have a namespace around the classes right? Because when I remove the namespace (and fixup the .svc file) then I get the same error you do.

    This is a known problem with the ADO.NET Data Services. We don't really support correctly if the classes defining entities don't have any namespace. To fix this just add the namespace around the classes (as you do have above) and it should just work.

    Thanks,
    Vitek Karas [MSFT]