Ich muss ein Bild in meiner PostgreSQL-Datenbank speichern, das ich mit dem Code von Entity Framework 6 geschrieben habe, und es über Npgsql zuordnen.Den Code von Entity Framework verwenden Zuerst ein Bild in PostgreSQL speichern
Other questions asked zu dem Thema schlägt eine byte[]
vor. PostgreSQL kann jedoch byte[]
nicht verwenden. Es kann jedoch einen Typ bytea
verwenden, der ein byte array ist. Aber wie bekomme ich diesen Typ in C#?
Edit:
ich eine Annahme gemacht, dass es die byte[]
war, die nicht erstellt werden konnte. Ich habe eine Update-Database -verbose
und es gab mir folgendes:
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'.
Die Klasse Ich versuche, hinzuzufügen:
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
}
Ich bin nicht ganz sicher, welche Art nicht von Npgsql behoben ist