title: EF Core | Need to use Navigation property for update on one property, but not another (Modules)
body: <p>I have a file table where I am adding a FK to a module table to add in which module it is coming from.</p>
  <p>When we create the record into FileSystemItems, we need to also update FileSystemItemsDatas as well.</p>
  <p>We do this with the below code:</p>
  <pre><code>        public async Task&lt;int&gt; CreateFileSystemItem(FileSystemItemCreateDTO fileSystemItem)
          {
              if (fileSystemItem == null)
              {
                  throw new ArgumentNullException(nameof(fileSystemItem));
              }
  
              var fileSystemItemToCreate = new FileSystemItems()
              {
                  FileName = fileSystemItem.FileName,
                  FileType = fileSystemItem.FileType,
                  IsFolder = fileSystemItem.IsFolder,
                  LastWriteTime = fileSystemItem.LastWriteTime,
                  ParentId = fileSystemItem.ParentId,
                  FileMetadata = fileSystemItem.FileMetadata,
                  ModuleId = fileSystemItem.ModuleId,
              };
  
              fileSystemItemToCreate.FileSystemItemData.FileData = fileSystemItem.FileData;
  
              BIContext.FileSystemItems.Add(fileSystemItemToCreate);
  
              await SaveChangesAsync().ConfigureAwait(false);
  
              return fileSystemItemToCreate.FileId;
          }
  </code></pre>
  <p>Then I'm seeing this error though:</p>
  <pre><code>Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while updating the entries. See the inner exception for details. ---&gt; System.Data.SqlClient.SqlException: Cannot insert the value NULL into column 'DisplayName', table 'Core.Modules'; column does not allow nulls. INSERT fails.
  The statement has been terminated.
     at System.Data.SqlClient.SqlCommand.&lt;&gt;c.&lt;ExecuteDbDataReaderAsync&gt;b__180_0(Task`1 result)
     at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
     at System.Threading.Tasks.Task.Execute()
  --- End of stack trace from previous location where exception was thrown ---
  </code></pre>
  <p>I know that I am adding into FileSytemItemsData via my navigation property, but how to I make sure I do not update the .Modules navigation property, because I do not need to in this case.</p>
  <p>FileSystemItems.cs</p>
  <pre><code>/// &lt;summary&gt;
      /// File System Item
      /// &lt;/summary&gt;
      public partial class FileSystemItems
      {
          /// &lt;summary&gt;
          /// Initializes a new instance of the &lt;see cref=&quot;FileSystemItems&quot;/&gt; class.
          /// &lt;/summary&gt;
          public FileSystemItems()
          {
              ItemChildren = new HashSet&lt;FileSystemItems&gt;();
              FileSystemItemData = new FileSystemItemDatas();
              Module = new Modules();
          }
  
          /// &lt;summary&gt;
          /// Gets or sets the file identifier.
          /// &lt;/summary&gt;
          /// &lt;value&gt;
          /// The file identifier.
          /// &lt;/value&gt;
          public int FileId { get; set; }
  
          /// &lt;summary&gt;
          /// Gets or sets the parent identifier.
          /// &lt;/summary&gt;
          /// &lt;value&gt;
          /// The parent identifier.
          /// &lt;/value&gt;
          public int? ParentId { get; set; }
  
          /// &lt;summary&gt;
          /// Gets or sets the name of the file.
          /// &lt;/summary&gt;
          /// &lt;value&gt;
          /// The name of the file.
          /// &lt;/value&gt;
          public string FileName { get; set; }
  
          /// &lt;summary&gt;
          /// Gets or sets the type of the file.
          /// &lt;/summary&gt;
          /// &lt;value&gt;
          /// The type of the file.
          /// &lt;/value&gt;
          public string FileType { get; set; }
  
          /// &lt;summary&gt;
          /// Gets or sets a value indicating whether this instance is folder.
          /// &lt;/summary&gt;
          /// &lt;value&gt;
          ///   &lt;c&gt;true&lt;/c&gt; if this instance is folder; otherwise, &lt;c&gt;false&lt;/c&gt;.
          /// &lt;/value&gt;
          public bool IsFolder { get; set; }
  
          /// &lt;summary&gt;
          /// Gets or sets the last write time.
          /// &lt;/summary&gt;
          /// &lt;value&gt;
          /// The last write time.
          /// &lt;/value&gt;
          public DateTime LastWriteTime { get; set; }
  
          /// &lt;summary&gt;
          /// Gets or sets the file system item data identifier.
          /// &lt;/summary&gt;
          /// &lt;value&gt;
          /// The file system item data identifier.
          /// &lt;/value&gt;
          public int? FileSystemItemDataId { get; set; }
  
          /// &lt;summary&gt;
          /// Gets or sets the module identifier.
          /// &lt;/summary&gt;
          /// &lt;value&gt;
          /// The module identifier.
          /// &lt;/value&gt;
          public int? ModuleId { get; set; }
  
          /// &lt;summary&gt;
          /// Gets or sets the file metadata.
          /// &lt;/summary&gt;
          /// &lt;value&gt;
          /// The file metadata.
          /// &lt;/value&gt;
          public string FileMetadata { get; set; }
  
          /// &lt;summary&gt;
          /// Gets or sets the file system item data.
          /// &lt;/summary&gt;
          /// &lt;value&gt;
          /// The file system item data.
          /// &lt;/value&gt;
          public FileSystemItemDatas FileSystemItemData { get; set; }
  
          /// &lt;summary&gt;
          /// Gets or sets the item children.
          /// &lt;/summary&gt;
          /// &lt;value&gt;
          /// The item children.
          /// &lt;/value&gt;
          public virtual ICollection&lt;FileSystemItems&gt; ItemChildren { get; set; }
  
          /// &lt;summary&gt;
          /// Gets or sets the parent item.
          /// &lt;/summary&gt;
          /// &lt;value&gt;
          /// The parent item.
          /// &lt;/value&gt;
          public virtual FileSystemItems ParentItem { get; set; }
  
          /// &lt;summary&gt;
          /// Gets or sets the module.
          /// &lt;/summary&gt;
          /// &lt;value&gt;
          /// The module.
          /// &lt;/value&gt;
          [System.Diagnostics.CodeAnalysis.SuppressMessage(&quot;Naming&quot;, &quot;CA1716:Identifiers should not match keywords&quot;, Justification = &quot;It's a Module&quot;)]
          public virtual Modules Module { get; set; }
      }
  </code></pre>
  <p>Modules.cs</p>
  <pre><code>    /// &lt;summary&gt;
      /// Module
      /// &lt;/summary&gt;
      [System.Diagnostics.CodeAnalysis.SuppressMessage(&quot;Naming&quot;, &quot;CA1716:Identifiers should not match keywords&quot;, Justification = &quot;It's a Module&quot;)]
      [Table(&quot;Modules&quot;, Schema = &quot;Core&quot;)]
      public partial class Modules
      {
          /// &lt;summary&gt;
          /// Gets or sets the module identifier.
          /// &lt;/summary&gt;
          /// &lt;value&gt;
          /// The module identifier.
          /// &lt;/value&gt;
          public int ModuleId { get; set; }
  
          /// &lt;summary&gt;
          /// Gets or sets the name.
          /// &lt;/summary&gt;
          /// &lt;value&gt;
          /// The name.
          /// &lt;/value&gt;
          public string Name { get; set; }
  
          /// &lt;summary&gt;
          /// Gets or sets the display name.
          /// &lt;/summary&gt;
          /// &lt;value&gt;
          /// The name.
          /// &lt;/value&gt;
          public string DisplayName { get; set; }
  
          /// &lt;summary&gt;
          /// Gets or sets the extension identifier.
          /// &lt;/summary&gt;
          /// &lt;value&gt;
          /// The extension identifier.
          /// &lt;/value&gt;
          public int ExtensionId { get; set; }
  
          /// &lt;summary&gt;
          /// Gets or sets the file system items.
          /// &lt;/summary&gt;
          /// &lt;value&gt;
          /// The file system items.
          /// &lt;/value&gt;
          public virtual ICollection&lt;FileSystemItems&gt; FileSystemItems { get; set; }
      }
  </code></pre>
  <p>FileSystemItemsDatas.cs</p>
  <pre><code>    /// &lt;summary&gt;
      /// File system item data
      /// &lt;/summary&gt;
      public partial class FileSystemItemDatas
      {
          /// &lt;summary&gt;
          /// Initializes a new instance of the &lt;see cref=&quot;FileSystemItemDatas&quot;/&gt; class.
          /// &lt;/summary&gt;
          public FileSystemItemDatas()
          {
              FileSystemItems = new HashSet&lt;FileSystemItems&gt;();
          }
  
          /// &lt;summary&gt;
          /// Gets or sets the file data identifier.
          /// &lt;/summary&gt;
          /// &lt;value&gt;
          /// The file data identifier.
          /// &lt;/value&gt;
          public int FileDataId { get; set; }
  
  #pragma warning disable CA1819 // Properties should not return arrays
                                /// &lt;summary&gt;
                                /// Gets or sets the file data.
                                /// &lt;/summary&gt;
                                /// &lt;value&gt;
                                /// The file data.
                                /// &lt;/value&gt;
          public byte[] FileData { get; set; }
  #pragma warning restore CA1819 // Properties should not return arrays
  
          /// &lt;summary&gt;
          /// Gets or sets the file system items.
          /// &lt;/summary&gt;
          /// &lt;value&gt;
          /// The file system items.
          /// &lt;/value&gt;
          public ICollection&lt;FileSystemItems&gt; FileSystemItems { get; set; }
      }
  </code></pre>
  <p>modelBuilder code:</p>
  <pre><code>            modelBuilder.Entity&lt;FileSystemItemDatas&gt;(entity =&gt;
              {
                  entity.HasKey(e =&gt; e.FileDataId);
              });
  
              modelBuilder.Entity&lt;FileSystemItems&gt;(entity =&gt;
              {
                  entity.HasKey(e =&gt; e.FileId);
  
                  entity.Property(e =&gt; e.FileName)
                      .IsRequired()
                      .HasMaxLength(255)
                      .IsUnicode(false);
  
                  entity.Property(e =&gt; e.FileType)
                      .IsRequired()
                      .HasMaxLength(50)
                      .IsUnicode(false);
  
                  entity.Property(e =&gt; e.FileMetadata).IsRequired().HasColumnType(&quot;nvarchar(max)&quot;).HasDefaultValue(&quot;[{}]&quot;);
  
                  entity.Property(e =&gt; e.LastWriteTime).HasColumnType(&quot;datetime&quot;);
  
                  entity.HasOne(d =&gt; d.FileSystemItemData)
                     .WithMany(p =&gt; p.FileSystemItems)
                     .HasForeignKey(d =&gt; d.FileSystemItemDataId)
                     .HasConstraintName(&quot;FK_FileSystemItems_FileSystemItemDatas&quot;);
  
                  entity.HasOne(d =&gt; d.Module)
                      .WithMany(p =&gt; p.FileSystemItems)
                      .HasForeignKey(d =&gt; d.ModuleId)
                      .HasConstraintName(&quot;FK_FileSystemItems_ModuleId&quot;);
  
                  entity.HasOne(d =&gt; d.ParentItem)
                      .WithMany(p =&gt; p.ItemChildren)
                      .HasForeignKey(d =&gt; d.ParentId)
                      .HasConstraintName(&quot;FK_FileSystemItems_FileSystemItems&quot;);
  
                  entity.HasOne(d =&gt; d.ParentItem)
                      .WithMany(p =&gt; p.ItemChildren)
                      .HasForeignKey(d =&gt; d.ParentId)
                      .HasConstraintName(&quot;FK_FileSystemItems_FileSystemItems&quot;);
              });
  
              modelBuilder.Entity&lt;Modules&gt;(entity =&gt;
              {
                  entity.HasKey(e =&gt; e.ModuleId);
  
                  entity.Property(e =&gt; e.Name)
                      .IsRequired()
                      .HasMaxLength(200)
                      .IsUnicode(false);
  
                  entity.Property(e =&gt; e.DisplayName)
                      .IsRequired()
                      .HasMaxLength(200)
                      .IsUnicode(false);
              });
  </code></pre>