C# WPF project entity framework не будет добавлять запись в БД
Hello all I have a C# WPF project and I added Entity Framework to it with a ADO.net data model. I have a .mdf database with a table in it and data. When I call the data.ToList() method I get the correct data from my db into my datagrid. So that is correct. The issue I am having is when I go to create/insert a new file into the database the record does not get saved. I also get 0 errors. I been reading online for hours trying to figure this out and so far all I came up with is maybe its because of my connection string because I have |data directory| or something like that it is maybe? I can also load the user into the screen when I send the selected user to the next screen I have created. Just cannot figure out why my user will not save to the database.
//connstring – <connectionStrings> <add name="EFcontext" connectionString="metadata=res://*/EFModel.csdl|res://*/EFModel.ssdl|res://*/EFModel.msl;provider=System.Data.SqlClient;provider connection string="data source=(LocalDB)\MSSQLLocalDB;attachdbfilename=|DataDirectory|\EntityFramewordDB.mdf;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" /> </connectionStrings> public class CRUD { //get the entity framework model context that was created. private EFcontext framework = null; public CRUD() { framework = new EFcontext(); } public Person GetPersonById(int personId) { return framework.People.Find(personId); } public List<Person> GetAllPeopleByList() { return framework.People.ToList(); } public void CreatePerson(Person person) { if(person != null) { framework.People.Add(person); framework.SaveChanges(); } } public partial class MainWindow : Window { private CRUD entityFramework; private Person dataGridPerson; public MainWindow() { InitializeComponent(); entityFramework = new CRUD(); PopulateDataGrid(); } private void PopulateDataGrid() { DataGridPeople.ItemsSource = entityFramework.GetAllPeopleByList(); } private void BtnCreate_Click(object sender, RoutedEventArgs e) { Window CreatePerson = new CreateUpdateWindow(); CreatePerson.Show(); Close(); } public partial class CreateUpdateWindow : Window { private CRUD entityFramework; private Person personWindowObject; public CreateUpdateWindow() { InitializeComponent(); entityFramework = new CRUD(); private void BtnSave_Click(object sender, RoutedEventArgs e) { Person personObject = new Person(); Window mainWindow = new MainWindow(); DateTime dateNow = DateTime.Now; personObject.DateCreated = dateNow; entityFramework.CreatePerson(personObject); MessageBox.Show("Created new person.", "Created"); mainWindow.Show(); Close(); } } //copied all sections of my code what is being used for creating user and to add 2 db
Что я уже пробовал:
глядя в интернете в течение нескольких часов, пытаясь по-разному, может быть, проблема connstring не уверена?