locked
Problem following MSDN sample code - appears to need CTP? RRS feed

  • Question

  • I have been trying to use the sample code in the article "How to: Customize Feeds with the Reflection Provider (WCF Data Services)" at http://msdn.microsoft.com/en-us/library/ee373838.aspx which is part of the .NET Framework 4 documentation.  However it refers to a version of the EntityPropertyMappingAttribute attribute and the SyndicationCriteria enumeration that aren't in the .NET Framework 4 RTM.  I believe they are part of the Microsoft Data Services June 2011 CTP, however I have downloaded and installed that and the Entity Framework June 2011 CTP and still cannot find the new SyndicationCriteria enumeration and the version of EntityPropertyMappingAttribute that takes it as a parameter.

    What am I doing wrong??

    Thursday, August 4, 2011 2:51 PM

Answers

  • Sorry for the confusion. Due to a problem with our snippet code branching, we ended up including code snippets from a previous pre-release version of WCF Data Services in the .NET Framework 4 documentation. I am working to get this fixed ASAP.

    In the meantime, the attribute should look like the attribute for the Url property of the Item type (below) when you are using the Microsoft Data Services June 2011 CTP:

    using System;
    using System.Collections.Generic;
    using System.Data.Services;
    using System.Data.Services.Common;
    using System.Linq;
    
    namespace CustomDataService
    {
      [EntityPropertyMappingAttribute("Customer", 
        SyndicationItemProperty.AuthorName,
        SyndicationTextContentKind.Plaintext, true)]
      [EntityPropertyMapping("OrderId", 
        SyndicationItemProperty.Title, 
        SyndicationTextContentKind.Plaintext, false)]
      [DataServiceKeyAttribute("OrderId")]
      public class Order
      {
        public int OrderId { get; set; }
        public string Customer { get; set; }
        public IList<Item> Items { get; set; }
      }
      [EntityPropertyMappingAttribute("Product",
        SyndicationItemProperty.CategoryTerm,
        true, SyndicationCriteria.CategoryScheme,
        "http://northwindtraders.com/Products")]
      [EntityPropertyMappingAttribute("Url",
        SyndicationItemProperty.LinkHref, false,
        SyndicationCriteria.LinkRel,
        "http://northwindtraders.com/ProductUrl")]
      [DataServiceKeyAttribute("Product")]
      public class Item
      {
        public string Product { get; set; }
        public int Quantity { get; set; }
        public string Url { get; set; }
      }
      public partial class OrderItemData
      {
        #region Populate Service Data
        static IList<Order> _orders;
        static IList<Item> _items;
        static OrderItemData()
        {
          _orders = new Order[]{
           new Order(){ OrderId=0, Customer = "Peter Franken", Items = new List<Item>()},
           new Order(){ OrderId=1, Customer = "Ana Trujillo", Items = new List<Item>()}};
          _items = new Item[]{
           new Item(){ Product="Chai", Quantity=10, 
             Url="http://northwindtraders.com/Teas" },
           new Item(){ Product="Chang", Quantity=25, 
             Url="http://northwindtraders.com/Specialty"},
           new Item(){ Product="Aniseed Syrup", Quantity = 5, 
             Url="http://northwindtraders.com/Specialty"},
           new Item(){ Product="Chef Anton's Cajun Seasoning", 
             Quantity=30, Url="http://northwindtraders.com/Spices"}};
          _orders[0].Items.Add(_items[0]);
          _orders[0].Items.Add(_items[1]);
          _orders[1].Items.Add(_items[2]);
          _orders[1].Items.Add(_items[3]);
        }
        #endregion
        public IQueryable<Order> Orders
        {
          get { return _orders.AsQueryable(); }
        }
        public IQueryable<Item> Items
        {
          get { return _items.AsQueryable(); }
        }
      }
    
      public class OrderItems : DataService<OrderItemData>
      {
        // This method is called only once to initialize
        //service-wide policies.
        public static void InitializeService(DataServiceConfiguration
                           config)
        {
          config.SetEntitySetAccessRule("Orders",
            EntitySetRights.AllRead |
            EntitySetRights.AllWrite);
          config.SetEntitySetAccessRule("Items",
            EntitySetRights.AllRead |
            EntitySetRights.AllWrite);
          config.DataServiceBehavior.MaxProtocolVersion = 
            DataServiceProtocolVersion.V3;
        }
      }
    }
    

    Thanks for letting us know about this.

    Glenn Gailey


    Please visit my blog

    This posting is provided "AS IS" with no warranties, and confers no rights.
    Thursday, August 4, 2011 9:56 PM

All replies

  • Hi,

    Thanks for reporting the problem, I will let the right people know who can fix this.

    Meanwhile, you're right that the code requires the CTP. But the CTP uses a newer version of the API which doesn't have the SyndicationCriteria parameter. It should be as simple as just not passing that parameter in. The new constructor should just take the string value (the criteria value). We realized that we don't need the SyndicationCriteria since it's obvious from the other parameters of the constructor.

    Thanks,


    Vitek Karas [MSFT]
    Thursday, August 4, 2011 8:45 PM
    Moderator
  • Sorry for the confusion. Due to a problem with our snippet code branching, we ended up including code snippets from a previous pre-release version of WCF Data Services in the .NET Framework 4 documentation. I am working to get this fixed ASAP.

    In the meantime, the attribute should look like the attribute for the Url property of the Item type (below) when you are using the Microsoft Data Services June 2011 CTP:

    using System;
    using System.Collections.Generic;
    using System.Data.Services;
    using System.Data.Services.Common;
    using System.Linq;
    
    namespace CustomDataService
    {
      [EntityPropertyMappingAttribute("Customer", 
        SyndicationItemProperty.AuthorName,
        SyndicationTextContentKind.Plaintext, true)]
      [EntityPropertyMapping("OrderId", 
        SyndicationItemProperty.Title, 
        SyndicationTextContentKind.Plaintext, false)]
      [DataServiceKeyAttribute("OrderId")]
      public class Order
      {
        public int OrderId { get; set; }
        public string Customer { get; set; }
        public IList<Item> Items { get; set; }
      }
      [EntityPropertyMappingAttribute("Product",
        SyndicationItemProperty.CategoryTerm,
        true, SyndicationCriteria.CategoryScheme,
        "http://northwindtraders.com/Products")]
      [EntityPropertyMappingAttribute("Url",
        SyndicationItemProperty.LinkHref, false,
        SyndicationCriteria.LinkRel,
        "http://northwindtraders.com/ProductUrl")]
      [DataServiceKeyAttribute("Product")]
      public class Item
      {
        public string Product { get; set; }
        public int Quantity { get; set; }
        public string Url { get; set; }
      }
      public partial class OrderItemData
      {
        #region Populate Service Data
        static IList<Order> _orders;
        static IList<Item> _items;
        static OrderItemData()
        {
          _orders = new Order[]{
           new Order(){ OrderId=0, Customer = "Peter Franken", Items = new List<Item>()},
           new Order(){ OrderId=1, Customer = "Ana Trujillo", Items = new List<Item>()}};
          _items = new Item[]{
           new Item(){ Product="Chai", Quantity=10, 
             Url="http://northwindtraders.com/Teas" },
           new Item(){ Product="Chang", Quantity=25, 
             Url="http://northwindtraders.com/Specialty"},
           new Item(){ Product="Aniseed Syrup", Quantity = 5, 
             Url="http://northwindtraders.com/Specialty"},
           new Item(){ Product="Chef Anton's Cajun Seasoning", 
             Quantity=30, Url="http://northwindtraders.com/Spices"}};
          _orders[0].Items.Add(_items[0]);
          _orders[0].Items.Add(_items[1]);
          _orders[1].Items.Add(_items[2]);
          _orders[1].Items.Add(_items[3]);
        }
        #endregion
        public IQueryable<Order> Orders
        {
          get { return _orders.AsQueryable(); }
        }
        public IQueryable<Item> Items
        {
          get { return _items.AsQueryable(); }
        }
      }
    
      public class OrderItems : DataService<OrderItemData>
      {
        // This method is called only once to initialize
        //service-wide policies.
        public static void InitializeService(DataServiceConfiguration
                           config)
        {
          config.SetEntitySetAccessRule("Orders",
            EntitySetRights.AllRead |
            EntitySetRights.AllWrite);
          config.SetEntitySetAccessRule("Items",
            EntitySetRights.AllRead |
            EntitySetRights.AllWrite);
          config.DataServiceBehavior.MaxProtocolVersion = 
            DataServiceProtocolVersion.V3;
        }
      }
    }
    

    Thanks for letting us know about this.

    Glenn Gailey


    Please visit my blog

    This posting is provided "AS IS" with no warranties, and confers no rights.
    Thursday, August 4, 2011 9:56 PM
  • The MSDN documentation has been fixed so that the code sample matches the topic version.
    Please visit my blog

    This posting is provided "AS IS" with no warranties, and confers no rights.
    Thursday, September 8, 2011 1:49 AM