Entity Framework не вставляет данные в файл .mdf в приложении windowform - PullRequest
0 голосов
/ 23 мая 2018

Я использую приложение windowform для вставки данных в файл .mdf, который находится в папке AppData, и файл .edmx в папке проекта.

Код вставки здесь:

   Customer newCustomer = new Customer();
    newCustomer.CustomerName = txtCustomerName.Text;
    newCustomer.ShopName = txtShopName.Text;
    newCustomer.PersonalPhone = txtPersonalPhoneNo.Text;
    newCustomer.ShopPhone= txtShopPhone.Text;
    newCustomer.Address = txtShopAddress.Text;
    newCustomer.Province = cbProvince.SelectedItem.ToString();
    using (NobelDBEntities1 entity = new NobelDBEntities1())
     {
       entity.Customers.Add(newCustomer);
       entity.SaveChanges();
     }

Файл App.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
  </startup>
  <connectionStrings>
    <add name="NobelDBEntities1" connectionString="metadata=res://*/NobelModel.csdl|res://*/NobelModel.ssdl|res://*/NobelModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=(LocalDB)\MSSQLLocalDB;attachdbfilename=|DataDirectory|\AppData\NobelDB.mdf;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;"
      providerName="System.Data.EntityClient" />
    <add name="NobelFactoryOrderingSystem.Properties.Settings.NobelDBConnectionString"
      connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\AppData\NobelDB.mdf;Integrated Security=True"
      providerName="System.Data.SqlClient" />
  </connectionStrings>

  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>

Примечание:

я пробовал все другие примеры переполнения стека, но не получил никакогоподходящее решение, любая помощь будет оценена!

...