What is Opf3? Why is Opf3? How is Opf3? All these burning questions and issues discussed here.
 | |
| | I'm sure there is a simple answer but I couldn't find it in the documentation and I'm new to opf3. How do I execute a stored procedere into an object collection? Many of our sprocs are used to implement paging so if there is an alternative I'd be curious of that as well.
Thanks in advance, Al
|
 | |
| | Hi,
you could use the ObjectReader in combination with the ObjectSet to do paging! The ObjectSet has a constructor that allows you to specify a ObjectReader and the range from where you want the objects to be populated. Internally Opf3 will then skip these objects that are not required!
A sample usage would be:
ObjectSet<Foo> os = null; using (ObjectReader<Foo> or = context.GetObjectReader<Foo>()) { // Go to 10th result and load 20 objects. os = new ObjectSet<Foo>(or, 10, 20); }
I hope this helps you!
Christian
|
 | |
| | Christian Liensberger wrote:
Hi, you could use the ObjectReader in combination with the ObjectSet to do paging! The ObjectSet has a constructor that allows you to specify a ObjectReader and the range from where you want the objects to be populated. Internally Opf3 will then skip these objects that are not required! A sample usage would be: ObjectSet<Foo> os = null; using (ObjectReader<Foo> or = context.GetObjectReader<Foo>()) { // Go to 10th result and load 20 objects. os = new ObjectSet<Foo>(or, 10, 20); }
Would that not return all rows from the DB then filter for the ten or so rows. I think it is more efficient to use the db to do the filtering and only return the 10 rows to the object collection. Oracle (and now sql 2005) both support the row_number function which makes this very easy and very fast to do.
As far as executing a sproc it seems the following syntax would work: { SqlQuery sq = new SqlQuery("sprocNameHere",parameters, go, here, in , order); sq.CommandType = CommandType.StoredProcedure; ObjectSet<TroubleTicket> TroubleTickets = context.GetObjectSet<TroubleTicket>(sq); }
Is that correct?
I've only been messing with opf3 for a few days since we just bought it but so far I am very impressed. Great job and keep it up!
-Al
|
 | |
| | Hi,
yes. Your way is possible and would execute the query.
Christian
|
 | |
| | Unfortunately it is not working and the documentation is a little scarce on the topic. I'm getting an error stating the sproc is not getting the expected parameter. Is there a way to define named parameters?
Currently I tried:
IDataParameter jurisIDB = CreateParameter(0, ref juris, "02", stringtype, storage); IDataParameter pageNumIDB = CreateParameter(1,ref pageNum, 5, stringint, storage); IDataParameter pageSizeIDB = CreateParameter(2, ref pageSize, 5, stringint, storage); IDataParameter orderByIDB = CreateParameter(3,ref orderBy, "status", stringtype, storage);
//I can stop here and view the various parameters and all the names, types and values are set correctly
SqlQuery sq = new SqlQuery("usp_TroubleTicketListing", jurisIDB, pageNumIDB, pageSizeIDB, orderByIDB); sq.CommandType = CommandType.StoredProcedure; ObjectSet<TroubleTicket> TroubleTickets = context.GetObjectSet<TroubleTicket>(sq);
The parameters are supplied in the order the sproc is expecting them and the sproc works when executed. Any help you can provide is greatly appreciated.
Thanks in advance, Al
|
 | |
| | Hi,
you just need it to do as if this is a normal query:
SqlQuery query = new SqlQuery("EXECUTE storedprocname {0}, {1}, {2}", "foo", 1, DateTime.Now); query.CommandType = CommandType.StoredProcedure;
The parameters are created automatically by Opf3!
Regards, Christian
|
 | |
| | Success! Thanks for your assistance it worked great.
Al
|