Note that there are some explanatory texts on larger screens.

plurals
  1. POInsert Entity into EntityCollection w/ RIA
    primarykey
    data
    text
    <p>I've got a one-to-many relationship set up. (Ex. A Person with many Phone Numbers). In my get query i have <code>this.ObjectContext.Person.Include("PhoneNumbers")</code> and the in generated MetaData including <code>public EntityCollection&lt;PhoneNumbers&gt; PhoneNumbers{ get; set; }</code> I have also set up a DTO with this and other properties i need.</p> <pre><code>[Include] [Association("Name","thisKey","otherKey")] public IEnumerable&lt;PhoneNumbers&gt; PNums { get; set; } </code></pre> <p>I can retrieve all the data alright, and display it in silverlight, but when I create a new one I run into problems. I've got this kind of thing going on:</p> <pre><code>private void Button_Click(object sender, System.Windows.RoutedEventArgs e) { if (dgMMs.SelectedItem != null) { PhoneNumbers wb = new PhoneNumbers (); wb.this = tbThis.Text; wb.that = tbThat.Text; wb.other = tbOther.Text; wb.whatnot = tbwhatnot.Text; ((Person)dgMMs.SelectedItem).PNums.Add(wb); } } </code></pre> <p>Then I get this error when calling <code>TDataSource.SubmitChanges();</code>:</p> <blockquote> <p>Message = "Submit operation failed validation. Please inspect Entity.ValidationErrors for each entity in EntitiesInError for more information."</p> </blockquote> <p>Alright, So i did that, and sure enough there is an error, but I don't quite understand why there is. I have a non-nullable field in the database for a last_modified_by field which i didn't set when I created it and added it to the entityCollection, and I guess this would be causing it, but my question comes from why RIA doesn't call my Insert method in my service that I've created because I want to set that field there. Like so:</p> <pre><code>public void InsertPhoneNumber(PhoneNumbers pnum) { pnum.last_modified = DateTime.Today; pnum.last_modified_by = Thread.CurrentPrincipal.Identity.Name; if ((pnum.EntityState != EntityState.Detached)) { this.ObjectContext.ObjectStateManager.ChangeObjectState(pnum, EntityState.Added); } else { this.ObjectContext.PhoneNumbers.AddObject(pnum); } } </code></pre> <p>But it's like RIA adds my object and calls it own Insert Method. So I rolled with it at first, and just set the property up in the UI, then it would give me this error: </p> <blockquote> <p>Message = "Submit operation failed. An error occurred while updating the entries. See the inner exception for details. Inner exception message: Cannot insert explicit value for identity column in table 'iset_trkr_writeback' when IDENTITY_INSERT is set to OFF."</p> </blockquote> <p>I never set the identity field to anything, I thought RIA would do this for me. But when i debug and take a look, it has a 0 for the value. But at least this time it calls my insert method in my service... Maybe I'm missing a big something for my process, but I really could use some help. Thanks:) </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.
    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