Ajouter des données à la base de données en utilisant le pattern MVVM

Je suis en train d'Enregistrer les Données dans la base de données.

Supposons que j'ai une Table Nommée Customers de trois champs:

Id
FirstName
LastName

J'ai créé mes modèles à l'aide de ADO.Net Modèle de Données d'Entité.

Voici mon ViewModel code

public class myViewModel : INotifyPropertyChanged
{

    private string _firstName;
    public string FirstName
    {
        get
        {
            return _firstName;
        }
        set
        {
            _firstName = value;
            OnPropertyChanged("FirstName");
        }
    }

    private string _lastName;
    public string LastName
    {
        get
        {
            return _lastName;
        }
        set
        {
            _lastName = value;
            OnPropertyChanged("LastName");
        }
    }

    protected virtual void OnPropertyChanged(string PropertyName)
    {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (handler != null)
        {
            handler(this, new PropertyChangedEventArgs(PropertyName));
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;

}

Voici ma MainWindow.fichier xaml:

<Window x:Class="Lab_Lite.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:vm="clr-namespace:Lab_Lite.ViewModels"
        Title="MainWindow" Height="350" Width="525" WindowState="Maximized">

    <Window.DataContext>
        <vm:MainWindowViewModel />
    </Window.DataContext>

    <Grid>

        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

        <TextBlock Grid.Row="0" Grid.Column="0" Text="FirstName" />
        <TextBox Grid.Row="0" Grid.Column="1" Text="{Binding FirstName, Mode=TwoWay, UpdateSourceTrigger=Explicit}" />

        <TextBlock Grid.Row="1" Grid.Column="0" Text="LastName" />
        <TextBox Grid.Row="1" Grid.Column="1" Text="{Binding LastName, Mode=TwoWay, UpdateSourceTrigger=Explicit}" />

        <Button Grid.Row="2" Grid.Column="1" Content="Save" />

    </Grid>

</Window>

J'ai deux problèmes ici:

1) How my ViewModel knows that FirstName property declared in ViewModel is 
   referenced to FirstName Column in my database?
2) How to save changes to database when UpdateSourceTrigger is set to Explicit?

Je pense avoir trouvé la réponse à la 2ème question jusqu'à une certaine mesure, à l'aide de la Commande. Mais je ne sais pas si c'est bon ou pas car je ne sais pas la réponse à ma première question.

Mise à jour:

Supposons que j'ai deux tables comme ceci :

Client:

CustomerID
Name
GenderID //Foreign Key

Genre :

GenderID
Value

Maintenant ce que doit être la valeur de CurrentCustomer.Gender dans SaveCustomerChanges Méthode ?

OriginalL'auteur Khushi | 2013-12-09