title: Mapping Models in ViewModels by handling undefined property call in C#
body: <p>I'm trying to map database entities (EntityFramework 4.1) to ViewModel (MVMMLight Framework). Creating property in VM for every database field would do the job, however it doesn't feel right, and will be hard to maintain later when we talk about mapping 46 database tables. Example code:</p>
  
  <pre><code>public const string MyPropertyPropertyName = "MyProperty";
  
  public string MyProperty
  {
      get
      {
          return _object.MyProperty;
      }
  
      set
      {
          if (_object.MyProperty != value)
          {
              _object.MyProperty = value;
              RaisePropertyChanged(MyPropertyPropertyName);
          }             
      }
  }
  </code></pre>
  
  <p>where <code>_object</code> is a stored <code>EntityObject</code> of a ViewModel's specified type.</p>
  
  <p>I was thinking about using dynamic properties like this</p>
  
  <pre><code>public object this[string propertyName]
  {
      get
      {
          System.Reflection.PropertyInfo property = _object.GetType().GetProperty(propertyName);
          if (property == null)
              return null;
  
          return property.GetValue(_object, null);
      }
  }
  </code></pre>
  
  <p>But binding it with <code>{Binding MyProperty}</code> results in <code>BindingExpression path error: 'MyProperty' property not found</code>, so it doesn't seem to be the right way.</p>
  
  <p>Is there a way to handle undefined properties in my own class? I think it would do the job.
  Maybe I'm trying to over maneuver this whole thing with mapping and there is already some nice, clean way to do this? If yes, I would like to know.</p>