Editable

Topics: Questions
Jan 17, 2013 at 8:35 AM

Hello

Is there anywhere an example how to use Editable, BeginEdit, CancelEdit and so on.

Tahnks

Jan 17, 2013 at 8:38 AM

See the official IEditableObject interface documentation by Microsoft.

And of course the getting started guide of Catel.

Jan 17, 2013 at 9:02 AM

Ok.

Is there any solution in catel to do a deep copy of an object?

Jan 17, 2013 at 9:11 AM

As you can see in the docs, the ModelBase implements the IClonable interface. It should deep-clone a modelbase.

Jan 17, 2013 at 9:21 AM
Edited Jan 17, 2013 at 9:21 AM

Ok. So I can make a copy of an Model.

My Problem is that I have in my Model a List of Objects loaded with the entityframework.

Now I like to edit an object of this list. The SelectedItem in an ListView. So I have to make a copy of my entityframework object.

So at the moment I don't know how to get this technics togehter: Catel, EntityFramwork, IEditable...

Jan 17, 2013 at 6:19 PM

Combining it all should be done with care. EntityFramework provides entities. Entities can be considered models. However, it is a very bad idea to deep-clone model graphs (think of all the entity states, event subscriptions, etc). Actually, the way you combine Catel with entity framework does not differ from any other framework. Just try it and watch what happens with care.

Jan 18, 2013 at 6:20 AM

I'm use Entity Framework Code First and derive all code first classes from ModelBase and using modelprop snippet for all properties in the entity class. in this way all things works correctly for me.

is this a bad idea?

Jan 18, 2013 at 7:43 AM

Just make sure that you profile your app once in a while. The ModelBase in Catel provides lots of functionality, but this might make the materialization (db => C# objects) slower. You might be interested in the LeanAndMean property during materialization. This will disable PropertyChanged notifications and validation.

Jan 18, 2013 at 8:59 AM

Thanks.

But I cant understand your answer completely. can you explain more? how to disable propertychanged and validation on loading?

Jan 19, 2013 at 12:34 PM

In the entity constructor where the DB data is materialized:

public void Materialize() // I have no idea how this is done in EF code first, that's up to you to find out
{
    LeanAndMeanModel = true;

    // Set your values here

    LeanAndMeanModel = false;
}