I am using VisualStudio 2015 and SqlServerExpress2015.
I have 3 Tables in SQLExpress:
I startet to create a new WPF Projetct in VisualStudio 2015 I added a new item - Ado.NET Entity Data Model I choose EF Designer from Database
I got this Model.
I aded a Datasource from Object And added the ProductBase as a Grid. I also add the Validation_Duration_Days and Validation_Amount as Edit Field.
Then I dod the follwoing coding.
public partial class MainWindow : Window
{
CarWashFlatEntities2 context = new CarWashFlatEntities2();
public MainWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
System.Windows.Data.CollectionViewSource productBaseViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("productBaseViewSource")));
// Laden Sie Daten durch Festlegen der CollectionViewSource.Source-Eigenschaft:
context.ProductBase.Load();
productBaseViewSource.Source = context.ProductBase.Local;
}
private void button_Click(object sender, RoutedEventArgs e)
{
context.SaveChanges();
productBaseDataGrid.Items.Refresh();
}
protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
{
base.OnClosing(e);
this.context.Dispose();
}
}
}
Result is , that I can add BaseProducts. I can also change the duration or validity amount values IF data exist's in the database.
MY question: When I add a row in the list ( productbase) and enter some value in the Vality_Amount textbox.. This will not work. How can I do this ? Adding a new row to ProductBase and also Adding a new row to ProductPrePaid with the same ProductBaseID.
Here are my models: ProductBase.cs
public partial class ProductBase
{
public int ProductBaseID { get; set; }
public string Name { get; set; }
public virtual ProductFlatRate ProductFlatRate { get; set; }
public virtual ProductPrePaid ProductPrePaid { get; set; }
}
ProductFlatRate.cs
public partial class ProductFlatRate
{
public int ProductBaseID { get; set; }
public int Validity_Duration_Days { get; set; }
public virtual ProductBase ProductBase { get; set; }
}
ProductPrePaid.cs
public partial class ProductPrePaid
{
public int ProductBaseID { get; set; }
public int Validity_Amount { get; set; }
public virtual ProductBase ProductBase { get; set; }
}