title: How can i get the ID from an Object after SaveChangesAsync()
body: <p>I have two Objects</p>
  <ul>
  <li>Post</li>
  <li>Image</li>
  </ul>
  <p>I upload Images with my create_post Controller and want to create image objects after the creation of my posts. I want to add the PostId in my image objects but i dont know how i get the postID after the SaveChangesAsync().</p>
  <p>This is my code:</p>
  <pre><code>        public async Task&lt;IActionResult&gt; CreatePost([FromForm]PostModel post)
      {
          var user = User.FindFirst(&quot;UserID&quot;)?.Value;
          if (post.content != null &amp;&amp; user != null)
          {
              var postdata = new Posts
              {
                  Content = post.content,
                  CreatorId = user,
                  Created = DateTime.Now
              };
              context.Posts.Add(postdata);
              await context.SaveChangesAsync();
  
              if (post.Images != null)
              {
                  foreach (var file in post.Images){
                      var image = new Images
                      {
                          userId = user,
                          postId = post.Id
                      };
  
                      var uniqueFileName = GetUniqueFileName(file.FileName);
                      var uploads = Path.Combine(hostingEnvironment.WebRootPath, &quot;Images/PostImages&quot;);
                      var filePath = Path.Combine(uploads, uniqueFileName);
                      await file.CopyToAsync(new FileStream(filePath, FileMode.Create));
                      image.imageFilePath = filePath;
  
                  }
              }
  
              return Ok(post);
  
          }
          else
          {
              return BadRequest(new { ErrorMessage = &quot;Textfeld darf nicht leer sein!&quot; });
          }
      }
  </code></pre>
  <p>Can someone please help me?</p>