Hi,
Well first of all, you could have a look at the following:
Creating a Generic Entity Framework 4.0 Repository[
^] - this will allow you to create a generic repository which will accommodate any entity table class.
Secondly, as mentioned earlier you could do something like this:
I don't know if you are using MVVM or any other design pattern, so this is going to be a very basic example:
Our Interface:
public interface ISavable
{
int SaveData();
}
Our first UserControl - which implement ISavable:
public partial class UserControl1 : UserControl, ISavable
{
public UserControl1()
{
InitializeComponent();
}
#region ISavable Members
public int SaveData()
{
using (DevelopmentEntities context = new DevelopmentEntities())
{
context.Events.AddObject(new Event());
return context.SaveChanges();
}
}
#endregion
}
Our second UserControl - which implements ISavable:
public partial class UserControl2 : UserControl, ISavable
{
public UserControl2()
{
InitializeComponent();
}
#region ISavable Members
public int SaveData()
{
using (DevelopmentEntities context = new DevelopmentEntities())
{
context.EventTypes.AddObject(new EventType());
return context.SaveChanges();
}
}
#endregion
}
Now, within our
main class (where ever the ribbon control is instantiated), we need to cast the
active user control to the interface and call the appropriate method - as mentioned earlier, this is a
very basic example, but demonstrates the principle:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
ISavable saveUserControl = this.DataContext as UserControl1;
saveUserControl.SaveData();
ISavable saveUserControl2 = this.DataContext as UserControl2;
saveUserControl.SaveData();
}
}
Needless to say you could extend this by making it more generic as well as implementing a MVVM pattern.
Hope it helps!
Kind regards,