Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* present in Insert.xaml.cs */
- private void button1_Click(object sender, RoutedEventArgs e)
- { if (textBox1.Text.Length > 0)
- {
- DB.Interventi newInterventi = new DB.Interventi
- {
- Element =textBox1.Text,
- Note =textBox1.Text.Length,
- //I use a listPicker for select element
- Category = (DB.Elements)listPicker.SelectedItem
- };
- MessageBox.Show("data insert");
- }
- else
- {
- MessageBox.Show("Insert Element");
- }
- App.ViewModel.SaveDB(); }
- /* class Elementi.cs */
- [Table]
- public class Elementi : INotifyPropertyChanged, INotifyPropertyChanging
- {
- // definisco ID degli elementi del'auto
- private int _id;
- [Column(DbType = "INT NOT NULL IDENTITY", IsDbGenerated = true, IsPrimaryKey = true)]
- public int Id
- {
- get { return _id; }
- set
- {
- NotifyPropertyChanging("Id");
- _id = value;
- NotifyPropertyChanged("Id");
- }
- }
- private string _elemento;
- [Column]
- public string Elemento
- {
- get { return _elemento; }
- set
- {
- NotifyPropertyChanging("Elemento");
- _elemento = value;
- NotifyPropertyChanged("Elemento");
- }
- }
- [Column(IsVersion = true)]
- private Binary _version;
- // Define the entity set for the collection side of the relationship.
- private EntitySet<Interventi> _allInterventi;
- // ASSOCIATION
- [Association(Storage = "_allInterventi", OtherKey = "_categoryId", ThisKey = "Id")]
- public EntitySet<Interventi> AllInterventi
- {
- get { return this._allInterventi; }
- set { this._allInterventi.Assign(value); }
- }
- public Elementi()
- {
- _allInterventi = new EntitySet<Interventi>(
- new Action<Interventi>(this.add_Intervento),
- new Action<Interventi>(this.remove_Intervento)
- );
- }
- // add
- private void add_Intervento(Interventi interv)
- {
- NotifyPropertyChanging("Interventi");
- interv.Category = this;
- }
- // remove
- private void remove_Intervento(Interventi interv)
- {
- NotifyPropertyChanging("Interventi");
- interv.Category = null;
- }
- /* class Interventi.cs*/
- [Table]
- public class Interventi : INotifyPropertyChanged, INotifyPropertyChanging
- {
- private int _InterventoId;
- [Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)]
- public int InterventoId
- {
- get { return _InterventoId; }
- set
- {
- if (_InterventoId != value)
- NotifyPropertyChanged("InterventoId");
- this._InterventoId = value;
- NotifyPropertyChanged("InterventoId");
- }
- }
- private string _Element;
- [Column(CanBeNull = false)]
- public string Element
- {
- get { return _Element; }
- set {
- if (_Kilometraggio != value)
- {
- NotifyPropertyChanging("Element");
- _Kilometraggio = value;
- NotifyPropertyChanged("Element");
- }
- }
- }
- private string _Note;
- [Column(CanBeNull = true)]
- public string Note
- {
- get { return _Note; }
- set
- {
- if (_Note != value)
- {
- NotifyPropertyChanging("Note");
- _Note = value;
- NotifyPropertyChanged("Note");
- }
- }
- }
- [Column(IsVersion = true)]
- private Binary _version;
- [Column]
- internal int _categoryId;
- private EntityRef<Elementi> _category;
- //ASSOCIATION
- [Association(Storage = "_category", ThisKey = "_categoryId", OtherKey = "Id", IsForeignKey = true)]
- public Elementi Category
- {
- // setto il get
- get { return _category.Entity; }
- set
- {
- NotifyPropertyChanging("Category");
- _category.Entity = value;
- if (value != null)
- {
- _categoryId = value.Id;
- }
- NotifyPropertyChanging("Category");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement