データベーステーブルを表すクラス(エンティティ)がいくつかあります
public class ALBUM
{
public int Id { get; set; }
public string Name { get; set; }
public int Tracks { get; set; }
}
public class BOOK
{
public int Id { get; set; }
public string Author { get, set; }
}
次に、それぞれのストアドプロシージャのパラメータを取得するには、挿入、更新、
public Command getParameters(string spName, dynamic entity, Connection conn)
{
Command cmd = conn.CreateCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = spName;
// Get properties (fields) from entity (table)
PropertyInfo[] properties = entity.GetType().GetProperties();
for (int = 0; i < properties.Length; i++)
{
// here I set Parameters: name, DBType, and Value from properties
}
}
今私は電話します
public void Some()
{
ALBUM someAlbum = new ALBUM();
BOOK anyBook = new BOOK(); // all respective data from DB is set
Command newCommand = getParameters("myAlbumSP", someAlbum, myConnection);
Command newCommand = getParameters("mySPBooks", anyBook, myConnection);
}
動的ではなく、「エンティティ」パラメータを他にどのように定義しますか?
それはうまくいきます、ただ私はそれをする他の方法を探しています、私はたくさんあると確信しています。