This is a migrated thread and some comments may be shown as answers.

Insert master and detail data with WCF RIA Service

9 Answers 163 Views
Getting Started
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Henk
Top achievements
Rank 1
Henk asked on 06 Oct 2010, 01:43 PM
In a Silverlight client with a WCF RIA Service I want to insert Master and Detail data in one submit.
To explain what I mean I use the Telerik OA.SL4.RIA.Demo application and model.
In the model there is a 'Rental Order' and a 'Customer' linked to the Rental Order.
In the Domain model on the server in the class 'Rental Order' there is a property named "Customer" with a reference to the Customer.
On the SIlverlight client I don't see the reference properties in the generated classes. I only have the key fields available of the referenced objects.
I want to do something like this (inserting a new Customer and a new RentalOrder in one submit):

Customer newCustomer = new Customer();
newCustomer.Address = "[Address]";
newCustomer.City = "[City]";
newCustomer.Country = "[Country]";
                  
RentalOrder newRentalOrder = new RentalOrder();
newRentalOrder.Customer = newCustomer;
  
dbContext.RentalOrders.Add(newRentalOrder);
dbContext.SubmitChanges();

I could also do something like the code below. But that is not an option because in my own application the Key fields (in this example the CustomerID) is generated on the server. So when I need to fill the CustomerID field of the newRentalOrder the CustomerID is not available yet.

PS: we used Oracle as backend and the PK in the master and child are generated using a sequence in a before insert trigger.

Customer newCustomer = new Customer();
newCustomer.CustomerID = 100;
newCustomer.Address = "[Address]";
newCustomer.City = "[City]";
newCustomer.Country = "[Country]";
  
dbContext.Customers.Add(newCustomer);
  
RentalOrder newRentalOrder = new RentalOrder();
newRentalOrder.CustomerID = newCustomer.CustomerID;
  
dbContext.RentalOrders.Add(newRentalOrder);
dbContext.SubmitChanges();

Can you tell me why in the object classes the reference properties are not available on the Silverlight client?
Is it not implemented yet or is it a bug. If it is not implemented yet can you tell me when this will be available?
Is there a possible workaround?

Kind Regards.

9 Answers, 1 is accepted

Sort by
0
PetarP
Telerik team
answered on 12 Oct 2010, 03:09 PM
Hello Henk,

 The reference properties are currently not generated out of the box. So for example if you have a relationship order->order details where one order has many orders in order to have the collection generated you will have to add some attributes to the already generated classes. For example if you have a collection of order details in your order class you will have to add the following above your property that is representing the collection:

[Include]  
        [System.ComponentModel.DataAnnotations.Association("Order_OrderDetails_FK","OrderID","OrderID")]
        publicvirtualIList<OrderDetail> OrderDetails
        {
            get
            {
                returnthis.orderDetails;
            }
        }

Save and rebuild your project. This will trigger our RIA provider implementation to pick up this association and generate the proper client code.
We are planning to extend our RIA support and include a wizard that will help you add all those attributes automatically however until then they need to be added manually.

Best wishes,
Petar
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Henk
Top achievements
Rank 1
answered on 13 Oct 2010, 02:00 PM
Hello Petar,

Thanks for your answer.
I tried your suggestion and added the assocation to the master object.
When I try to insert a master and a detail with the following code, In the database the ID field in the detail referencing the master in the Detailtable is Null instead of the ID of the master.
 
Master newMaster = new Master();
Detail newDetail = new Detail();
newMaster.Details.Add(newDetail);
  
dbContext.Masters.Add(newMaster);
  
dbContext.SubmitChanges();

I also tried to add an assocation in the detail object to the property referencing the master object.
I removed the assocation in the master object because I received an error when I added the assocations in both.
If I insert master and detail with the code below everything works OK.

Master newMaster = new Master();
Detail newDetail = new Detail();
newDetail.Master = newMaster;
  
dbContext.Details.Add(newDetail);
  
dbContext.SubmitChanges();

But I want a reference to the details in the master and a reference to the master in the detail on the client.
I tried adding the assocations in both the master and the detail class with the extra parameter "IsForeignKey" I found.

I added in the detail:

[System.ComponentModel.DataAnnotations.Association("FK", "ID", "ID", IsForeignKey = true)]


And in the master:

[System.ComponentModel.DataAnnotations.Association("FK", "ID", "ID", IsForeignKey = false)]


When I now try to insert master and detail using both methods explained the master record is insert once and the detail record is inserted twice.

Do you have a solution?

Kind Regards.
0
PetarP
Telerik team
answered on 18 Oct 2010, 04:19 PM
Hello Henk,

 Can you please look into your OpenAccess configuration file and ensure that the Managed option is set to true for your details collection? Basically we have tried to achieve scenarios similar to yours and so far we did not have any problems. We will be grateful for any further information you can share with us regarding your model.

Sincerely yours,
Petar
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Henk
Top achievements
Rank 1
answered on 19 Oct 2010, 11:39 AM
Hi,

Where can I find the 'Managed' option?
Also I don't have a configuration file. I am using a Domain Model.

Kind Regards.
0
PetarP
Telerik team
answered on 19 Oct 2010, 05:13 PM
Hello Henk,

 The domain model represents your configuration file. If you open your rlinq file with an xml editor you will see the configuration. Basically the Managed attribute should be placed in the collection tag representing your collection. Here is an example:

<orm:field name="orders" property="Orders" uniqueId="b908029d-6a9f-4623-b728-bd1de5cb5df4" type="ConsoleApplication2.Order">
           <orm:collection element-class="ConsoleApplication2.Order" Managed="true" inverse-field="customer" order-by="" uniqueId="8ca510a7-666d-43ae-adf8-a68a57fc3817" />
         </orm:field>


Kind regards,
Petar
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Henk
Top achievements
Rank 1
answered on 20 Oct 2010, 01:44 PM
Hi Petar,

I have checked the rlinq file: The Managed attribute is set to true.
Using both methods explained the master record is inserted once and the detail record is inserted twice.
The Identity Mechanism property of all Meta Classes is set to BackendCalculated because the key fields are filled by a database trigger. Can this be the cause of the problems?

Kind Regards.

0
PetarP
Telerik team
answered on 25 Oct 2010, 06:23 PM
Hi Henk,

 It seems there is a problem with our managed collections, however I fail to reproduce it. Everything works fine on my side. Can you perhaps provide us with a sample application that exposes the problem? We will be really grateful on your cooperation on the issue.
We look forward to your reply.

Kind regards,
Petar
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Henk
Top achievements
Rank 1
answered on 27 Oct 2010, 10:07 AM
Hi Petar,

I submitted a support ticket with ticket ID 361042 where I attached an example project to reproduce the problem.

Kind Regards.
0
PetarP
Telerik team
answered on 01 Nov 2010, 07:06 PM
Hi Henk,

 Thank you for the project. I suggest we continue our conversation in the support ticket you have opened. I will post here once we find a resolution to the problem so that the rest of the community can benefit should someone encounter the same problem.

All the best,
Petar
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Getting Started
Asked by
Henk
Top achievements
Rank 1
Answers by
PetarP
Telerik team
Henk
Top achievements
Rank 1
Share this question
or