我想从窗口代码中发送或能够访问数据库,所以我想在主窗口上添加一个构造函数并从 Program 类发送上下文,我在其中显示我的窗口并加载数据库,但是context在程序项目中,而我已经引用了window项目,所以不能循环引用
我有两个项目,一个用于 GUI,另一个包含所有类,包括实体框架数据库的上下文
class ProgramControl: DbContext
{
public DbSet<Asignaturas> Asigns { get; set; }
public DbSet<Alumno> Alumnos { get; set; }
public DbSet<Profesor> Profes { get; set; }
public DbSet<Aula> Aulas { get; set; }
}
public class Program
{
public static void Main(string[] args)
{
using (var db = new ProgramControl()) {
MainWindow mainWindow = new MainWindow();
mainWindow.Show();
}
}
}
public partial class MainWindow : Window
{
public static MainWindow AppWindow;
public MainWindow()
{
InitializeComponent();
AppWindow = this;
}
private void AlumnoButton_Click(object sender, RoutedEventArgs e)
{
Window1 window1 = new Window1();
window1.Show();
}
private void ExitButton_Click(object sender, RoutedEventArgs e)
{
Close();
}
private void AsignaturasButton_Click(object sender, RoutedEventArgs e)
{
Window2 window2 = new Window2();
window2.Show();
}
private void ProfesorButton_Click(object sender, RoutedEventArgs e)
{
Window3 window3 = new Window3();
window3.Show();
}
}
明月笑刀无情
相关分类