Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is my value (of a ComplexType) null for my SQL insert in WCF Data Service and Entity Framework 4?
    primarykey
    data
    text
    <p>I'm using EF 4, WCF Data Services and Silverlight 4. I have been getting data from my service without problems. I'm trying to save entities in a batch that are defined in EF with a complex type that has non-nullable columns. Ex: Customer has a Complex Type of Audit. Audit has an EntryDateTime column that is marked as computed (could that be the problem?). It also has an Address field that is required. In my Silverlight app, I have a form to enter customer info and the address info. On the save button click I do something like this:</p> <pre><code>Customer c = new Customer(); c.Name = this.nameTextBox.Text; // more properties set.... Customer.Audit = new Audit(){ UserId = 1, EntryDateTime = DateTime.UtcNow}; c.Address = new Address() { Address = this.addressTextBox.Text, ZipCode = this.zipcodeTextBox.Text, // more properties set.... Audit = new new Audit(){ UserId = 1, EntryDateTime = DateTime.UtcNow} }; EDM context = new EDM(new Uri(serviceURL, UriKind.Absolute)); // add to the context for the update context.AddToCustomers(c); context.AddToAddresses(c.Address); </code></pre> <p>// I'm not sure if the update is needed... context.UpdateObject(c); context.UpdateObject(c.Address);</p> <pre><code>// manually add the link according to http://msdn.microsoft.com/en-us/library/dd756361.aspx, this must be done for the context to know about the relationship (aka association) context.SetLink(c, "Address", c.Address); // save the changes (batch so all the objects will get created with associations) context.BeginSaveChanges(SaveChangeOptions.Batch, new AsyncCallback((iar) =&gt; { try { // Callback method for the async request, retrieves the status of the requested action DataServiceResponse response = this.Context.EndSaveChanges(iar); // Maps the status of the requested action </code></pre> <p>bool status = true; foreach (ChangeOperationResponse change in response) { if (!change.StatusCode > 200 &amp;&amp; change.StatusCode &lt; 300;) { status = false; break; } } if(!status) throw new Exception("something wrong with the save");</p> <p>I've set breakpoints and have seen the entryDateTime as set (in the EF designer.cs and before the saveChanges is called), but the server is always throwing an exception that the entryDateTime is null and cannot be for a non-nullable column for a database insert. I've also tried to attach and update the audit, but that didn't help either (as I expected).</p> <pre><code>context.AddLink(customer.Audit, "Audit", customer); context.UpdateObject(customer.Audit); </code></pre> <p>Is there something I'm missing?</p> <p>EDIT: I put the question up last night very quickly as I was on my way out. Thank you for the comments and hopefully I've made my question clear.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload