
Untitled
By: a guest on
Jul 29th, 2012 | syntax:
None | size: 1.08 KB | hits: 14 | expires: Never
How to add a child entity collection to an entity on its creation using datagridview selected rows
dgvTags.DataSource = _rs.Tags.Where(x => x.TagGroup.Name == "All Reasons").OrderBy(x => x.Name);
Line l = new Line
{
Part = o.Part,
Description = desc,
Price = o.Price.Value,
InvoiceNo = o.InvoiceNo,
Cost = o.Cost.Value,
Comments = txtComment.Text,
Tags = dgvTags.SelectedRows as List<Tag> // <--- needs work here
};
foreach (DataGridViewRow r in dgvTags.SelectedRows)
{
l.Tags.Add(r.DataBoundItem as Tag);
}
IList<Tag> myrows = dataGridView1.SelectedRows.Cast<DataGridViewRow>().Select(x => x.DataBoundItem as Tag).ToList();
Tags = new System.Data.Objects.DataClasses.EntityCollection<RS.Tag>(
dataGridView1.SelectedRows.Cast<DataGridViewRow>()
.Select(x => x.DataBoundItem as Tab).ToList());
dataGridView1.SelectedRows.Cast<DataGridViewRow>()
.Select(x => x.DataBoundItem as Tab).ToList().ForEach(y => Tags.Add(y));
foreach (DataGridViewRow r in dgvTags.SelectedRows)
{
l.Tags.Add(r.DataBoundItem as Tag);
}