title: Best way to validate IDbcommand parameter
body: <p>Let's say I have a class</p>
  
  <pre><code>public class foo { public string FooId { get; set; } }
  </code></pre>
  
  <p>Now in my Data layer, I am trying to write code which will create one instance of IDataCommand and set FooId as on of the command parameters something like this</p>
  
  <pre><code>public void save(foo f, IDbConnection conn)
  { 
      IDataCommand cmd = conn.CreateCommand(); 
      cmd.CommandName = "SP_SAVE_INFO" ; 
      IDataDbParameter param = cmd.CreateParameter(); 
      param.name = "@fooId"; 
      param.value=(f.id&gt;0)?f.id:(object)DbNull.Value;
      cmd.parameters.add(param);
      cmd.ExecuteNonQuery();
  }
  </code></pre>
  
  <p>If you notice code line - param.value=(f.FooId >0)?f.id:(object)DbNull.Value; . My question is exactly in this area. If I have too many parameters to be provided. It looks kind of bad when I check for value like this on every parameter. Question here is what is the best way to do this kind of thing? Who should do that DL or BL? If BL, then should it assign DBNull Value there? Is there any other standard way of doing this?</p>