title: linq2db insert with inheritance mapping
body: <p>I'm trying to test a complex example of linq2db mapping, that includes inheritance mapping and embedded object. I follow the example from the tests project, but get an exception on insert operation. I didn't find any examples of insert or update operations in the test project, so maybe I do something wrong. </p>
  
  <pre><code>    [Table]
      [Column("SomeString", "SomeModel.SomeString")]
      [InheritanceMapping(Code = "code1", Type = typeof(Child1))]
      [InheritanceMapping(Code = "code2", Type = typeof(Child2))]
      public abstract class Parent
      {
          [PrimaryKey]
          public int Id { get; }
  
          public SomeModel SomeModel { get; private set; }
  
          [Column(IsDiscriminator = true)]
          public string DType { get; set; }
  
          protected Parent(int id, SomeModel someModel)
          {
              Id = id;
              SomeModel = someModel;
          }
      }
  
      public class SomeModel
      {
          public SomeModel(string someString)
          {
              SomeString = someString;
          }
  
          [NotNull]
          public string SomeString { get; }
  
          internal SomeModel()
          {
          }
      }
  
      public class Child1 : Parent
      {
          public Child1(int id, SomeModel someModel, int threshold) : base(id, someModel)
          {
              Threshold = threshold;
              DType = "child1";
          }
  
          [Column]
          public int Threshold { get; }
      }
  
      public class Child2 : Parent
      {
          public Child2(int id, SomeModel someModel, string code) : base(id, someModel)
          {
              Code = code;
              DType = "child2";
          }
  
          [Column]
          public string Code { get; private set; }
      }
  
      [Test]
      [TestCase("Dont cast child in insert")]
      [TestCase("Cast child in insert")]
      public void TestInheritanceMapping(string testMode)
      {
          var db = new DbNorthwind();
          db.Execute(@"IF OBJECT_ID('dbo.Parent', 'U') IS NOT NULL 
                          drop table Parent");
          db.CreateTable&lt;Parent&gt;();
          Console.WriteLine(db.GetTable&lt;Child1&gt;().Select(c =&gt; c.Threshold).Any());
          switch (testMode)
          {
              case "Dont cast child in insert":
                  db.Insert(new Child1(1, new SomeModel("SomeString"), 1));
                  db.Insert(new Child2(1, new SomeModel("SomeString"), "somecode!"));
                  break;
              case "Cast child in insert":
                  db.Insert&lt;Parent&gt;(new Child1(1, new SomeModel("SomeString"), 1));
                  db.Insert&lt;Parent&gt;(new Child2(1, new SomeModel("SomeString"), "somecode!"));
                  break;
          }
      }
  
      public class DbNorthwind : DataConnection
      {
          public DbNorthwind() : base("SqlServer", From.ConnectionStrings.Get("storage.sqlserver"))
          {
          }
      }
  </code></pre>
  
  <p>On the "Dont cast child in insert" test case I get </p>
  
  <blockquote>
    <p>"System.Data.SqlClient.SqlException : Invalid object name 'Child1'."</p>
  </blockquote>
  
  <p>On the "Cast child in insert":</p>
  
  <blockquote>
    <p>"System.ArgumentException : "Threshold" is not a member of type"</p>
  </blockquote>
  
  <p>However the table "Parent" is created properly on the "db.CreateTable();" step:
  <a href="https://i.stack.imgur.com/89fY6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/89fY6.png" alt="enter image description here"></a></p>
  
  <p>Also the select operation seems to work</p>
  
  <p>Thanks for a help!</p>