Question

In the excellent mvvmcross-library I can use RIO binding to prevent unreadable code:

public INC<String>Title = new NC<String>();

Then I can read and write values using Title.Value. Makes the models much more readable.

Normally, this property would be written as: private string _title;

    public string Title
    {
        get { return _title; }
        set
        {
            _title = value;
            RaisePropertyChanged("Title");
        }
    }

But when I want to use sqlite-net, these fields cannot be streamed to the database because they are not basic types with a getter and setter.

I can think of a few options how to get around that:

  1. Make a new simple object that is similar to the model, but only with the direct db-fields. And create a simple import-export static method on the model. This also could prevent struggling with complex model-code that never needs to relate to the actual database.
  2. Make sqlite-net understand reading NC-fields. I read into the code of the mapper, but it looks like this is going to be a lot of work because it relies on the getter-setter. I did not find a way to insert custom mapping to a type, that could be generic.
  3. Remove RIO and just put in all the code myself instead of relying on RIO.

Maybe someone has some advice?

Was it helpful?

Solution

Thanks Stuart. It was exactly my thought, so I did implement it that way: my (DB) Models do not contain RIO. Only my viewmodels do, and they reference a Model that is DB-compatible.

So, for posterity the following tips: - Do not use RIO in your models that need to be database-backed. - Reference models in your viewmodels. In the binding you can use the . (dot) to reference this model.

This keeps them nicely separated. This gives you also another advantage: if you need to reuse a model (because the same object might be displayed twice on the screen), but under different circumstances, it is much easier to handle this situaties to find this already instantiated model.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top