Postgres access from custom dll with EF6

0

I have dll with data context

using rmclibrary.Model;
using System.Data.Entity;

namespace rmclibrary
{
    public class RmcContext : DbContext
    {
        public RmcContext() : base("RmcContext")
        {

        }
 public DbSet<Brand> Brands { get; set; }
// ...and etc
    }

}

In the Brand class I have Check method

public class Brand
    {
        [Key]
        public int BrandId { get; set; }
        public string UID1C { get; set; }
        [Required]
        public string Name { get; set; }
        [Required]
        public int Prefix { get; set; }

    public void Check()
        {
            Console.WriteLine("nachalo");
            using (var dc = new RmcContext())
            {

                var k = new Brand();
                k.Name = "trrr";
                k.Prefix = 4444;

                dc.Brands.Add(k);
                dc.SaveChanges();

            }

        }

    }

Below 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>
  <entityFramework>    
    <providers>      
      <provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, EntityFramework6.Npgsql" />      
    </providers>
  </entityFramework>
  <system.data>
  <DbProviderFactories>
    <add name="Npgsql Data Provider" invariant="Npgsql" support="FF" description=".Net Framework Data Provider for Postgresql" type="Npgsql.NpgsqlFactory, Npgsql" />
  </DbProviderFactories>
</system.data>
  <connectionStrings>    
    <add name="RmcContext" connectionString="Server=localhost;Port=5432;User Id=postgres;Password=123456789;Database=rmctest;" providerName="Npgsql" />
  </connectionStrings>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Npgsql" publicKeyToken="5d8b90d52f46fda7" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

Migration and Updating going with out ani problrms

this dll I'm add in new console project and try use Check method

using rmclibrary.Model;
using System;

    namespace DatabaseWorker
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("start");
                var z = new Brand();
                z.Check();            
            }
        }
    }

It is stuck on this line using (var dc = new RmcContext()) and after couple minute give error : System.Data.SqlClient.SqlException HResult=0x80131904 provider: SQL Network Interfaces, error: 26

c#
entity-framework
entity-framework-6
asked on Stack Overflow Oct 30, 2018 by Nevega • edited Oct 30, 2018 by Nevega

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0