title: C# how to execute a npsql command on a data base in a context file insted of using _context.Database.ExecuteSqlCommand for SQL
body: <p>I have a C# project that uses two providers : SQL and POSTGRESS.</p>
  <p>I have to run a command on the DB to turn IDENTITY_INSERT ON and OFF.</p>
  <p>I know how to do it in SQL :</p>
  <pre><code>_context.Database.ExecuteSqlCommand(@&quot;SET IDENTITY_INSERT [dbo].CustomerType ON&quot;);
  </code></pre>
  <p>But , how do I do the same thing with POSTGRESS  ?</p>
  <p>What I thought is :</p>
  <pre><code>NpgsqlCommand command = new NpgsqlCommand(@&quot;SET IDENTITY_INSERT [dbo].CustomerType ON&quot;);
  </code></pre>
  <p>But I am  not sure this is the way to do this .</p>
  <p>These are my line code :</p>
  <pre><code>var strategy = _context.Database.CreateExecutionStrategy();
                              strategy.Execute(() =&gt;
                              {
                                  using (var transaction = _context.Database.BeginTransaction())
                                  {
                                      bool isIsNpgsql = _context.Database.IsNpgsql();
  
                                      _context.CustomerType.Add(ManagementCustomerType);
                                      if (isIsNpgsql)
                                      {
                                         
                                          NpgsqlCommand command = new NpgsqlCommand(@&quot;SET IDENTITY_INSERT [dbo].CustomerType ON&quot;);
                                          _context.SaveChanges();
                                          NpgsqlCommand command = new NpgsqlCommand(@&quot;SET IDENTITY_INSERT [dbo].CustomerType OFF&quot;);
                                      }
                                      else
                                      {
                                              _context.Database.ExecuteSqlCommand(@&quot;SET IDENTITY_INSERT [dbo].CustomerType ON&quot;);
                                              _context.SaveChanges();
                                              _context.Database.ExecuteSqlCommand(@&quot;SET IDENTITY_INSERT [dbo].CustomerType OFF&quot;);
                                      }
                                      transaction.Commit();
                                  }
                              });
  </code></pre>
  <p>All help will be appraised !</p>