This website is intended as archive for old content and forums.
Please visit http://opf3.codeplex.com for the project's new website.

General Discussion

FORUM TOPIC

What is Opf3? Why is Opf3? How is Opf3? All these burning questions and issues discussed here.

RSS
Liviu Ursu
Posted on the 08/25/08 1:14 PM
ISelfContainedObject and dynamic configuration questions
Reply Quote
 Hi , i have following questions:


A: I want to implement custom object tracking.

I understand from the documentation how to mark my object as modified, but i want to control EXACTLY what fields are persisted to the datastore. I want to persiste only the
modified fields.

Is this possible?

B: Is it possible to configure the persistence programmatically, without attributes?
I want to be able to persist POCO object that i do not own, defined in other binaries.

Thank you



Alfred Ortega
Posted on the 08/25/08 2:48 PM
RE: ISelfContainedObject and dynamic configuration questions
Reply Quote
 

Liviu Ursu wrote:
A: I want to implement custom object tracking.

I understand from the documentation how to mark my object as modified, but i want to control EXACTLY what fields are persisted to the datastore. I want to persiste only the
modified fields.

Is this possible?

Customized the updatequery created. Check out: http://www.opf3.com/Opf3/Community/Topic.aspx?Forum=5&Topic=1224


Liviu Ursu wrote:
Hi , i have following questions:
B: Is it possible to configure the persistence programmatically, without attributes?
I want to be able to persist POCO object that i do not own, defined in other binaries.


You can implement the ITypeMappingProvider and roll your own:
http://www.opf3.com/Opf3/Community/Topic.aspx?Forum=5&Topic=588

or

Check out the XmlTypeMappingProvider documentation and use it.


Al


Liviu Ursu
Posted on the 08/25/08 6:43 PM
RE: ISelfContainedObject and dynamic configuration questions
Reply Quote
 Thank you for your quick reply....

The ITypeMappingProvider stuff is exactly what i need.

Customizing the update query, seems like i have to do all the property value convertions stuuf to the storage which might vary. I would have expected something like "telling" the OPF3 framework that only this List<PropertyInfo> has changed, so all he "heavy duty" stuff of constructing the query is delegated to OPF3 and not implemented "by hand"..

Any ideas how to do this?

Alfred Ortega
Posted on the 08/25/08 8:27 PM
RE: ISelfContainedObject and dynamic configuration questions
Reply Quote
 Unless you discover that there is indeed a performance issue it's really better to just let the framework do it's part vice troubleshooting performance problems that might not exist. It's likely that unless the record has hundreds of fields or BLOB information it's problably not going to make a noticable performance difference. Plus it kinda defeats the purpose using an ORM in the first place Huh! which is to accept the potential small trade-off in performance for a much faster development and maintenance time.

But if I had to do it for a class (after all performance testing showed I had too) it would be something like the code snippets show. Add the using System.Reflections and implement INotifyPropertyChanged and IObjectNotification to your object.

//have a place to store your fieldlist of fields that have changed
List<string> FieldList = new List<string>();


with INotifyPropertyChanged implemented you can tell everytime a property is changed - add the propertyname to your list (only once of courseSmile!)

            if(!FieldList.Contains(propertyName))
                FieldList.Add(propertyName);



  
I gues you could also override the GetUpdateQuery as shown in the example with something similar to this.


SqlQuery createUpdateQuery()
{
string sql = "Update YourDatabaseTable Set ";  //Sql Statement
object[] params = new object[FieldList.Length];//param values
Type type = this.GetType();
int i = 0;
foreach(string fieldname in FieldList)
{
  sql += fieldname + " = {" + i + "},";
  params(i)  = type.GetProperty(fieldname).GetValue(this, null) ;
  i++;
}
sql = sql.substring(0,sql.length-1); //remove the last comma
sql += " where RecordID = {" + i + "}";
params(i) = this._recordID; //represents your PK....
                return new SqlQuery(sql,params);
}


You should now have an SqlQuery ready for execution (WARNING UNTESTED CODE ALERT!!!Big Grin)

Edit- I had to change the [ to ( and ] to ) for the display to work right both places it has params(i)

hth,
Al

Christian Liensberger [Moderator]
Posted on the 08/26/08 2:05 AM
RE: ISelfContainedObject and dynamic configuration questions
Reply Quote
 Hey guys,

the framework offers also the SqlQueryBuilder for an easier way to create SQL queries with Opf3.

Opf3 offers also another interface that might be interesting for your scenario. It's called IPartialPersist and allows to specify which members need to be persisted: http://www.opf3.com/Opf3/Documentation/HTMLHelp/Chili.Opf3~Chili.Opf3.IPartialPersist.html

Christian

Alfred Ortega
Posted on the 08/26/08 2:15 PM
RE: ISelfContainedObject and dynamic configuration questions
Reply Quote
 Cool, what is the bool for in the _changes collection? I'm guessing to determine whether to persist or not which just makes me ask - then why put it in the collection at all?Huh!

Al

Christian Liensberger [Moderator]
Posted on the 08/26/08 3:22 PM
RE: ISelfContainedObject and dynamic configuration questions
Reply Quote
 Hi Al,

you could use another structure too. I have only used the dictionary in the example and put a bool in there (as dummy) because lookups in dictionaries are fast :)

Christian

All times are in GMT.