locked
is not a valid relationship for 1-0..1 relationships, the primary keys must be shared. error in lightswitch RRS feed

  • Question

  • I google for this error for hours with no luck:

    'myOrdersDetailEntities_myOrdersEntity' is not a valid relationship. For 1-0..1 relationships, the primary keys must be shared. This relationship will not be imported

    I have a lightswitch project with two datasources:

    01. SQL server database with two tables Orders and FactoryOrders with 1 to many relationship

    02. WCF ria service with the following two entities :

    public class myOrdersEntity
        {
            [Key]
            public int OrderID { get; set; }
            public DateTime OrderDate { get; set; }
            [Association("myOrdersDetailEntities_myOrdersEntity", "OrderID", "OrderID", IsForeignKey = false)]
            public myOrdersDetailEntity myOrdersDetailEntities { get; set; }
          
        }


        public class myOrdersDetailEntity
        {
            [Key]
            public int OrderDetailID { get; set; }
            public int OrderID { get; set; }
            public decimal Amount { get; set; }
           [Association("myOrdersDetailEntities_myOrdersEntity", "OrderID", "OrderID", IsForeignKey = true)]
            public myOrdersEntity myOrdersEntity { get; set; }

        }

      [Query(IsDefault = true)]
             public IQueryable<myOrdersEntity> GetAllOrdersService()
             {
                 var TheseOrders = from o in ObjectContext.Orders

                                   select new myOrdersEntity
                                               {
                                                   OrderID = o.OrderKey,
                                                   OrderDate = o.OrderDate,
                                               };
                 return TheseOrders;

             }

     


             [Query(IsDefault = true)]
             public IQueryable<myOrdersDetailEntity> GetAllOrdersDetailsService()
             {
                 var result = from myDetail in ObjectContext.FactoryOrders
                              select new myOrdersDetailEntity
                              {
                                  OrderDetailID = myDetail.FactoryOrderID,
                                  OrderID = myDetail.OrderKey,
                                  Amount = myDetail.Amount.Value,
                              };

                 return result;
             }

    What I'm missing in my code?

    Thanks,

    Rachida

     

     

     

            

                             

     

                

                


    Rachida Dukes

    Sunday, August 12, 2012 10:48 PM

Answers

  • I found the solution:

    public class myOrdersEntity
         {
             [Key]
             public int OrderID { get; set; }
             public DateTime OrderDate { get; set; }
                   
            [Association("myOrdersDetailEntities_myOrdersEntity", "OrderID", "OrderID", IsForeignKey = false)]
            public DataServiceCollection<myOrdersDetailEntity> myOrdersDetailEntity { get; set; }

        }

      public class myOrdersDetailEntity
         {
             [Key]
             public int OrderDetailID { get; set; }
             public int OrderID { get; set; }
             public decimal Amount { get; set; }

            [Association("myOrdersDetailEntities_myOrdersEntity", "OrderID", "OrderID", IsForeignKey = true)]
            public myOrdersEntity myOrdersEntities  { get; set; }

     
        }


    Rachida Dukes

    • Marked as answer by Rachida Monday, August 13, 2012 5:31 PM
    Monday, August 13, 2012 5:30 PM