CRUD -Betrieb auf .NET, WPF und Entity FrameworkC#

Ein Treffpunkt für C#-Programmierer
Anonymous
 CRUD -Betrieb auf .NET, WPF und Entity Framework

Post by Anonymous »

Ich habe ein Projekt "Enterprise Resource Planning". Es verwendet eine SQLite -Datenbank. : < /p>

Code: Select all

public class ArtistCollection : ObservableCollection
{
private ChinookdbContext _context;

public ArtistCollection(IEnumerable artists, ChinookdbContext context) : base(artists)
{
_context = context;
}

protected override void InsertItem(int index, Artist item)
{
Context.Artists.Add(item);
base.InsertItem(index, item);
Console.WriteLine("InsertItem");
}

protected override void RemoveItem(int index)
{
Context.Artists.Remove(this[index]);
base.RemoveItem(index);
}

public void Save()
{
try
{
Console.WriteLine("Clienti: Saved N° " + _context.SaveChanges());
}
catch (Exception ex)
{
System.Windows.MessageBox.Show(ex.ToString());
}
}

public ChinookdbContext Context
{
get
{
return _context;
}
}
}
< /code>
Dies ist meine modifizierte Entität: < /p>
public partial class Artist : INotifyPropertyChanged, IEditableObject
{
private Artist backup;
private bool inTransaction;
public event PropertyChangedEventHandler PropertyChanged;

protected void OnPropertyChanged(string name)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}

public void BeginEdit()
{
backup = new Artist();
backup.ArtistId = ArtistId;
backup.Name = Name;
inTransaction = true;
Console.WriteLine("- BeginEdit");
}

public void CancelEdit()
{
if (inTransaction)
{
ArtistId = backup.ArtistId;
OnPropertyChanged(nameof(ArtistId));

Name = backup.Name;
OnPropertyChanged(nameof(Name));

backup = null;
inTransaction = false;
Console.WriteLine("- CancelEdit");
}
}

public void EndEdit()
{
if (inTransaction)
{
OnPropertyChanged(nameof(ArtistId));
OnPropertyChanged(nameof(Name));
backup = null;
inTransaction = false;
Console.WriteLine("- EndEdit");
}
}
}
All dies für eine Tabelle. p>
Gibt es einen einfacheren Weg? < /p>

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post