How to execute nonquery using Repository?

Topics: General Discussion Forum
Apr 10, 2007 at 7:31 PM
I am new to Web Service Software Factory and need some help. I have a created a stored procedure that takes in a number of input parameters and also contains a few output parameters. I run into problems when using "Create data repository classes from business entities" guidance. First the menu does not contain an action of "Execute NonQuery", the only options include either selects, or updates, or inserts, or deletes. I select "Get one" and then in the next window when I select my stored procedure it doesn't provide me with any members of the stored proc to map to my business entity. Obviously I would like to use the Repository infrastructure to make calls to the database. I hope there is some flexibility or a work around to this problem. I appreciate your help.
Apr 11, 2007 at 1:27 AM
(I have no VS.NET in this machine, but) I think there is only a hand-work solution.

You have to create your own method in the repository class, and add a new <..>SelectionFactory class. (You can use as template 1, a normal selection (ie. GetAll) factory combined with 2, the input parameters of an insert method.) If you use same domain object as in the generated classes, the domain object factory is reusable.
Apr 11, 2007 at 6:08 PM

bojxx wrote:
(I have no VS.NET in this machine, but) I think there is only a hand-work solution.

You have to create your own method in the repository class, and add a new <..>SelectionFactory class. (You can use as template 1, a normal selection (ie. GetAll) factory combined with 2, the input parameters of an insert method.) If you use same domain object as in the generated classes, the domain object factory is reusable.



Thanks.
Apr 12, 2007 at 12:41 AM
Fragmens from the generated (and refactored) wssf code. Hope it helps:

ProductRepository
...
public Product GetProductByProductId(System.Int32 productId)
{
ISelectionFactory<System.Int32> selectionFactory = new GetProductsByProductIdSelectionFactory();

try
{
return base.FindOne(selectionFactory, new ProductFactory(), productId);
}
catch (SqlException ex)
{
HandleSqlException(ex, selectionFactory);
}

return new Product();
}
...

ProductFactory (Renamed from GetAllFromProductsFactory etc.)
...
public Product Construct(IDataReader reader)
{
Product product = new Product();

int basePriceIndex = reader.GetOrdinal("BasePrice");
...

GetProductsByProductIdSelectionFactory
...
public DbCommand ConstructSelectCommand(Database db, System.Int32 productId)
{

DbCommand command = db.GetStoredProcCommand(Resources.StoredProcedures.DboGetProductsByProductId);
db.AddInParameter(command, "productId", DbType.Int32, productId);
return command;
}
...