Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用实体框架';s首先在PostgreSQL中存储图像的代码_C#_Entity Framework_Postgresql_Ef Code First_Npgsql - Fatal编程技术网

C# 使用实体框架';s首先在PostgreSQL中存储图像的代码

C# 使用实体框架';s首先在PostgreSQL中存储图像的代码,c#,entity-framework,postgresql,ef-code-first,npgsql,C#,Entity Framework,Postgresql,Ef Code First,Npgsql,我需要在我的PostgreSQL数据库中存储一个图像,这是我首先用EntityFramework6的代码编写的,并通过Npgsql映射它 在主题中,建议使用字节[]。但是,PostgreSQL不能使用字节[]。但是,它可以使用名为bytea的类型,这是一种。但是我怎样才能在C#中得到这种类型呢 编辑: 我做了一个假设,就是不能创建的是字节[]。我做了一个更新数据库-verbose,它给了我以下信息: PM> Update-Database -verbose Using StartUp pr

我需要在我的PostgreSQL数据库中存储一个图像,这是我首先用EntityFramework6的代码编写的,并通过Npgsql映射它

在主题中,建议使用
字节[]
。但是,PostgreSQL不能使用
字节[]
。但是,它可以使用名为
bytea
的类型,这是一种。但是我怎样才能在C#中得到这种类型呢

编辑:

我做了一个假设,就是不能创建的是
字节[]
。我做了一个
更新数据库-verbose
,它给了我以下信息:

PM> Update-Database -verbose
Using StartUp project 'Core.Shell'.
Using NuGet project 'Core.Database'.
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
Target database is: 'TrackerDB' (DataSource: tcp://localhost:5432, Provider: Npgsql, Origin: Configuration).
Applying explicit migrations: [201604130907499_initial].
Applying explicit migration: 201604130907499_initial.
CREATE TABLE "public"."EmployeePhotoes"("EmployeePhotoId" int4 NOT NULL DEFAULT 0,"Image" bytea,"EmployeeId" int4 NOT NULL DEFAULT 0,CONSTRAINT "PK_public.EmployeePhotoes" PRIMARY KEY ("EmployeePhotoId"))
CREATE INDEX "EmployeePhotoes_IX_EmployeePhotoId" ON "public"."EmployeePhotoes" ("EmployeePhotoId")
ALTER TABLE "public"."EmployeePhotoes" ADD CONSTRAINT "FK_public.EmployeePhotoes_public.Employees_EmployeePhotoId" FOREIGN KEY ("EmployeePhotoId") REFERENCES "public"."Employees" ("EmployeeId")
ALTER TABLE "dbo"."__MigrationHistory" SET SCHEMA public
System.Runtime.Serialization.SerializationException: Type is not resolved for member 'Npgsql.NpgsqlException,Npgsql, Version=3.0.5.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7'.
    at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
    at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)
    at System.Data.Entity.Migrations.Design.ToolingFacade.Update(String targetMigration, Boolean force)
    at System.Data.Entity.Migrations.UpdateDatabaseCommand.<>c__DisplayClass2.<.ctor>b__0()
    at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
Type is not resolved for member 'Npgsql.NpgsqlException,Npgsql, Version=3.0.5.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7'.
我不完全确定Npgsql没有解析什么类型,这是因为GAC中没有安装Npgsql

通过安装最新版本的解决了此问题

public class EmployeePhoto
{
    //Primary key
    public int EmployeePhotoId { get; set; }

    public byte[] Image { get; set; }  

    //Foreign key
    public int EmployeeId { get; set; }

    //Navigation property
    public Employee Employee { get; set; } //1 photo for 1 Employee
}