This course will be retired on July 14, 2025.
Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll

- 2x 2x
- 1.75x 1.75x
- 1.5x 1.5x
- 1.25x 1.25x
- 1.1x 1.1x
- 1x 1x
- 0.75x 0.75x
- 0.5x 0.5x
Let's review how to use EF to create entities and implement the console application's Repository `AddComicBook` method.
Follow Along
To follow along commiting your changes to this course, you'll need to fork the dotnet-comic-book-gallery-model repo. Then you can clone, commit, and push your changes to your fork like this:
git clone <your-fork>
cd dotnet-comic-book-gallery-model
git checkout tags/v5.2 -b creating-entities
Exercise Solution
Here's the solution to the exercise that's suggested at the end of the video.
foreach (ComicBookArtist artist in comicBook.Artists)
{
if (artist.Artist != null && artist.Artist.Id > 0)
{
context.Entry(artist.Artist).State = EntityState.Unchanged;
}
if (artist.Role != null && artist.Role.Id > 0)
{
context.Entry(artist.Role).State = EntityState.Unchanged;
}
}
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up-
PLUS
Juan Ignacio Scopp
Courses Plus Student 291 Points1 Answer
-
Mark Ramos
19,209 Points1 Answer
View all discussions for this video
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up