This forum is used by the Opf3 developers to announce new features or to discuss with you about ideas on new features.
 | |
| | The good old DataManager is back (OPF.NET).
The next version of Opf3 will include a new interface, called IPersistentQueriesProvider. This interface is implemented by classes that create the query statements for the persistent's insert, update and delete operations.
An implementation looks like this:
public sealed class CallQueriesProvider : IPersistentQueriesProvider { public IQuery GetInsertQuery(IStorage storage, object persistent) { // Return the null to have the framework create the query. return null; } public IQuery GetUpdateQuery(IStorage storage, object persistent) { Call c = (Call)persistent; // Check if the storage is the MsSqlStorage. if (storage is MsSqlStorage) { // If that's true, create a custom query and return that query. return new SqlQuery("UPDATE CALLS SET DURATION = {0} WHERE ID = {1}", c.Duration, c.ID); } // Otherwise return null. return null; } public IQuery GetDeleteQuery(IStorage storage, object persistent) { // Return the null to have the framework create the query. return null; }
// Return the type of persistent this class has been created for. public Type PersistentType { get { return typeof(Call); } } }
The class in the sample provides the query statements for the Call persistent object (see PersistentType property). It is returning a custom query statement for the update operation (if the storage is MsSqlStorage). For all other operations the query created by the Opf3 Framework is returned.
Now, how to let Opf3 know that you want use this class to create the query statements? Nothing easier than that: The ObjectContext has a new property, called PersistentQueriesProviders. That property allows you to "register" an class that implements the IPersistentQueriesProvider interface. It looks like this:
context.PersistentQueriesProviders.Add(new CallQueriesProvider());
The persistent type is automatically fetched by querying the PersistentType property. Nothing you have to worry about!
This new addition allows you also to easily use stored procedures for insert, update and delete operations!
Greetings, Christian Liensberger
|