Wrraping Command Object

O

ofer

I'm Working on generic DAL component which can deal with all kind of
providers like SqlClient, SqlCe, OleDB, Odbc.



I was wrapping the command object with my own class that inherit from
IDBCommand and this class is holding instance of real command object (like
SqlCommand, OleDbCommand).



The problem is when I want to perform an update operation using DataAdapter
and
equivalent command object the DataAdapter reject my IDBCommand object with
the following exception:

"Update requires a valid InsertCommand when passed DataRow collection with
new rows."



I thought to inherit the concrete command (class MyCmd: SqlCommand)
but all those command are sealed.



Does anyone have any idea?



Thanks.



Bnaya Eshet C.T.O

Wise Mobility.
 
F

Frans Bouma [C# MVP]

ofer said:
I'm Working on generic DAL component which can deal with all kind of
providers like SqlClient, SqlCe, OleDB, Odbc.



I was wrapping the command object with my own class that inherit from
IDBCommand and this class is holding instance of real command object (like
SqlCommand, OleDbCommand).



The problem is when I want to perform an update operation using DataAdapter
and
equivalent command object the DataAdapter reject my IDBCommand object with
the following exception:

"Update requires a valid InsertCommand when passed DataRow collection with
new rows."



I thought to inherit the concrete command (class MyCmd: SqlCommand)
but all those command are sealed.



Does anyone have any idea?

You shouldn't use a derived class, you should use the interfaces. So
use IDbCommand in your generic DAL and use a factory for creating the
various specific commands.

FB

--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top