O
O
one__for__one2018-09-24 11:51:34
Entity Framework
one__for__one, 2018-09-24 11:51:34

How to save an object that contains a collection of other objects using Entity?

public class Position
    {
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
one__for__one, 2018-09-24
@one__for__one

public class Position
{
 public string ConsumptionRateUnit { get; set; }
public List<Operation> Operations { get; set; }
}
public class Operation
{
public int? Id_position { get; set; } 
public int? Id { get; set; }
public string FormValuation { get; set; }
}
var items = (from position in doc.Element("TechNorm").Elements("Position")
                             select new Position()
                             {
                              ...
                             }
using (var db = new LoadNsiContext())
                {
                    foreach (var operation in items)
                    {
                        db.Operations.Add(operation);
                    }
                    db.SaveChanges();
                }

There was an error cannot convert element type to iterator type in foreach (var operation in items)
How to save an object that contains a collection of other objects using Entity?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question