[Mono-list] Automatic Binding of Variables to Parameters in ADO.NET

Gonzalo Paniagua Javier gonzalo@ximian.com
27 Jan 2003 14:47:09 +0100


You can have the struct like:
public struct MyStruct
{
  [SQLInputValue]
  public int someNumber;
  [SQLOutputValue]
  public double someMonetaryValue;
  [SQlOutputValue]
  public DateTime someDataTime;
  [SqlOutputValue]
  public bool someBoolean;
}

SqlxxxValue also has a couple of constructors more, taking 1 and 2
strings.

public SqlxxxValue () (default value for columnName and fieldName is the
name of the field in the struct)

public SqlxxxValue (string columnName) (default value for fieldName is
either columnName or the name of the field in the struct at your
election)

public SqlxxxValue (string columnName, string fieldName)


Then in GetData you can substitute all occurrences of
MyStruct:field_name for all SqlInputValues.

Now, the pseudo-code for GetData:

public MyStruct GetData (IDbConnection dbconn, MyStruct input_st)
{
	1. Substitute all the :field_name by their values in input_st
	2. Substitute all output parameters using the provider's specific
syntax for output parameters and map them to the SqlOutputValues field
names.
	3. Retrieve the row and for each output column that has a mapping,
store the result in the struct field whose columnName matches.

	4. Voilą
}


Hope this helps.

Cheers.

-Gonzalo