Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 29th, 2012  |  syntax: None  |  size: 1.08 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to add a child entity collection to an entity on its creation using datagridview selected rows
  2. dgvTags.DataSource = _rs.Tags.Where(x => x.TagGroup.Name == "All Reasons").OrderBy(x => x.Name);
  3.        
  4. Line l = new Line
  5. {
  6.     Part = o.Part,
  7.     Description = desc,
  8.     Price = o.Price.Value,
  9.     InvoiceNo = o.InvoiceNo,
  10.     Cost = o.Cost.Value,
  11.     Comments = txtComment.Text,
  12.     Tags = dgvTags.SelectedRows as List<Tag> // <--- needs work here
  13.                     };
  14.        
  15. foreach (DataGridViewRow r in dgvTags.SelectedRows)
  16. {
  17.     l.Tags.Add(r.DataBoundItem as Tag);
  18. }
  19.        
  20. IList<Tag> myrows = dataGridView1.SelectedRows.Cast<DataGridViewRow>().Select(x => x.DataBoundItem as Tag).ToList();
  21.        
  22. Tags = new System.Data.Objects.DataClasses.EntityCollection<RS.Tag>(
  23.     dataGridView1.SelectedRows.Cast<DataGridViewRow>()
  24.     .Select(x => x.DataBoundItem as Tab).ToList());
  25.        
  26. dataGridView1.SelectedRows.Cast<DataGridViewRow>()
  27.     .Select(x => x.DataBoundItem as Tab).ToList().ForEach(y => Tags.Add(y));
  28.        
  29. foreach (DataGridViewRow r in dgvTags.SelectedRows)
  30. {
  31.     l.Tags.Add(r.DataBoundItem as Tag);
  32. }