0

i have probleme with entityframework code first , when i execute my app and save data to database in my controllers it dont't create table for my domain class, i have create context, and add a Dbset variable for my model , i verify all that we need for working with EF but i can't understand wath's the matter , here my code for saving data to dataabase :

 foreach (var data in my_friends) { entity.Friends.Add(data); } 

my_friends contain a list of "UserFriend" that's it's my domain class, entity it's the context, if you have meet this problem in the past , i like that you help me please !!

1 Answer 1

2

Try the following:

foreach (var data in my_friends) { entity.Friends.Add(data); } entity.SaveChanges(); 
Sign up to request clarification or add additional context in comments.

1 Comment

Personally, I would call SaveChanges() outside of the foreach loop. That way all of the database changes are done within a single transaction.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.