O
O
one__for__one2018-09-24 17:13:32
Entity Framework
one__for__one, 2018-09-24 17:13:32

Is it possible to cascade data using Entity Framework?

There are two classes: "ancestor" and "heirs". The class "ancestor" has a collection of heirs. It is possible to insert data cascadingly without doing a breadth or depth traversal (keep the ancestor, get the id, update the object, and then insert all descendants):

Predok nas = new Predok{Name = "Вася"}
db.Predok.add(nas);
db.SafeChange();
//взять id, обновить вставленного предка и вставлять всех наследников

But simply:
List<Naslednik>  Nasled = new <Naslednik>();
//заполняем List<Naslednik>
var PredokIn = new Predok {Name = "Вася", Nasledniki = Nasled}
db.Predok.add(PredokIn);

Answer the question

In order to leave comments, you need to log in

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

Yes, you can.

db.Predok.add(PredokIn);
- EF understands that.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question