I have no OrderSet Propertys

Oct 4, 2013 at 9:28 AM
Hi there,

I'am using DataBase first with 3 tables Product, Order and ProductOrder

In the example you have in both Product and Order a property OrderSet.
Where do they come from and what are these propertys? collections?
Do I have to create them by hand?

Btw I am using ObjectContext
Oct 5, 2013 at 8:19 PM
Hi,

The documentation explains how to expose an m2m association in your entity model to Ria services. It assumes that you're using code-first and DbContext. Unfortunately, the documentation contained an error (which I have fixed now), because the code example in the documentation incorrectly showed that both Product and Order have an OrderSet property. In fact, the product entity has a OrderSet property and the Order entity has a ProductSet property. These collection properties denote the two ends of the m2m relations as it exists in the entity model.

If you're using database first and have EF generate an edmx for you, then the OrderSet (or Orders, depending on how you named your properties in your entity model) and ProductSet (or Products) properties are generated for you by EF.

Since you're not using DbContext and code-first, it might help if you have a look at the demo application included in the source code before getting it to work with database first and ObjectContext since that requires some more work. The Dog / Trainer example gives you a concrete example about how the m2m relations for Ria services works and how it maps to an m2m relation in EF.

Good luck!
Oct 6, 2013 at 9:01 AM
Ok first of all I switched to DbContext to make it all a little easier, and server side code compiled OK.
Client side did not work until I changed both ICollection<ProductOrder> to have the same name like so:
namespace Test.Web {
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web.DomainServices.FluentMetadata;
    using RIAServices.M2M;
    using RIAServices.M2M.Configuration;

    #region ProductOrder

    public class ProductOrder : LinkTable<Product, Order> {

        //[Key]
        //public int ProductId { get; set; }

        //[Key]
        //public int OrderId { get; set; }

    }

    public partial class Product {

        public ICollection<ProductOrder> ProductOrders {
            get {
                return Orders.ProjectObject1(this, x => x.ProductOrders);
            }
        }
    }

    public partial class Order {

        public ICollection<ProductOrder> ProductOrders {
            get {
                return Products.ProjectObject2(this, x => x.ProductOrders);
            }
        }
    }

    public class MetadataConfiguration : IFluentMetadataConfiguration {

        public void OnTypeCreation(MetadataContainer metadataContainer) {
            metadataContainer.Entity<Product>()
                .Projection(x => x.Orders)
                .M2M(x => x.ProductOrders, x => x.ProductOrders, x => x.Products);
        }
    }

    #endregion ProductOrder


}
If I don't name them the same client side code breaks with:

Error 1 'Test.Web.ProductOrder' does not contain a definition for 'AttachProductToOrder_Product_ProductOrders'
Error 2 'Test.Web.ProductOrder' does not contain a definition for 'AttachOrderToProduct_Order_ProductOrders'


Are you aware of this? Or am I missing something?
Oct 8, 2013 at 8:21 AM
This is a bug. Thanks for reporting!
Oct 8, 2013 at 8:22 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Oct 8, 2013 at 8:33 AM
I've fixed the error and pushed new nuget packages