title: How to manage the foreign keys insertions in DB?
body: <p>I develop a little object parser (for SQL files that allows me to find easily the list of all tables used in a procedure) and I've the following model :</p>
  
  <p>3 tables :</p>
  
  <ul>
  <li>Object (ID, Name, LastWriteTime)</li>
  <li>Table (ID, Name)</li>
  <li>ObjectTable (ObjectID, TableID)</li>
  </ul>
  
  <p>I've the 3 corresponding classes :</p>
  
  <p>Object - List of files scanned:</p>
  
  <pre><code>[Table(Name = "object")]
  public class SourceFile : IEquatable&lt;SourceFile&gt;
  {
      public SourceFile()
      { }
  
      [Column(Name = "id", IsDbGenerated = true)]
      public Guid ID
      {
          get;
          set;
      }
  
      [Column(Name = "lastwritetime")]
      public DateTime LastWriteTimeUtc
      {
          get;
          set;
      }
  
      [Column(Name = "name", IsPrimaryKey = true)]
      public String Name
      {
          get;
          set;
      }
  
      public bool Equals(SourceFile other)
      {
          return Name == other.Name;
      }
  
      public override int GetHashCode()
      {
          return Name.GetHashCode();
      }
  }
  </code></pre>
  
  <p>Table - List of all tables in the DB: </p>
  
  <pre><code>[Table(Name = "table")]
  public class SourceTable : IEquatable&lt;SourceTable&gt;
  {
      public SourceTable()
      { }
  
      [Column(Name = "id", IsDbGenerated = true)]
      public Guid ID
      {
          get;
          set;
      }
  
      [Column(Name = "name", IsPrimaryKey = true)]
      public String Name
      {
          get;
          set;
      }
  
      public bool Equals(SourceTable other)
      {
          return Name == other.Name;
      }
  
      public override int GetHashCode()
      {
          return Name.GetHashCode();
      }
  }
  </code></pre>
  
  <p>ObjectTable - For each object, the list of table used :</p>
  
  <pre><code>[Table(Name = "object_table")]
  public class SourceFileTable
  {
      [Column(Name = "object_id", IsPrimaryKey = true)]
      public Guid ObjectID
      {
          get; set;
      }
  
      [Column(Name = "table_id", IsPrimaryKey = true)]
      public Guid TableID
      {
          get; set;
      }
  }
  </code></pre>
  
  <p>As you can see, the ID of object &amp; table are DBGenerated, so my question is, how can I add values in ObjectTable using the generated IDs? There only given once inserted in DB, not before.</p>
  
  <p>Any hint?</p>